In Tritium, How to insert any element between the children second and third anchor tag?

251 views Asked by At
 <div class="parent">
 <a class="cld1">1</a>
 <a  class="cld2">2</a> 
 <a  class="cld3" >3</a> 
 <a  class="cld4" >4</a>       
</div>

How to insert any element between the children second and third anchor tag?

3

There are 3 answers

0
maitry shah On BEST ANSWER
$('//div[@class="parent"]/a[@class="cld2"]') {
        insert_after('div','hii')
    } 

You can do like this to inset div in between tag Refer http://tester.tritium.io/18f12697fde014066894af356915af1471782732

0
BGoers On

Another way to do this if you want to target the number instead of the class is like so:

$('//div[@class="parent"]/a[contains(text(),"2")]') {
  insert_after('div', class:'example')        
} 
0
axysharma On

Another way of doing this is:

$('//div[@class="parent"]/a[position()=2]') {
    insert_after('div','Hello', class:'test')
    }

This way we need not to worry about enter code here the class change or text change also.