Changing an internal tag of a tag class using jquery or javascript

I have the following code:

<li id="toto" class="jstree-leaf"> <ins class="jstree-icon2">&nbsp;</ins> <a class=""><ins class="jstree-icon2">&nbsp;</ins>Story B</a> </li> 

I need to change the tag class <ins> for a specific <li> . I need to access id <li> and then change the class of all the <ins> tags found inside it

I would appreciate it if someone could show me the right way to do this.

Thanks a lot.

+4
source share
5 answers
 $("#toto ins").attr("class","className"); // all ins $("#toto ins:eq(0)").attr("class","className"); // first ins 
+2
source

You can add and remove classes for ins tags like this using jQuery:

 $('#toto ins').removeClass('oldClass').addClass('newClass'); 
+3
source
 $("#toto ins").removeClass().addClass("yourClass") 
+2
source
 $('#toto ins').attr('class', 'new-class'); 
+1
source

You can also use toggleClass for this:

 $("#toto ins").toggleClass("className"); 
0
source

Source: https://habr.com/ru/post/1379497/


All Articles