[Solved] Can I use jquery to operate the name attribute of tag?


Classes are our friend – forget trying to use a name attribute – this is not the correct use for that. What you want to do is add a class and then alter the display based on the class:

//HTML
<a href="https://stackoverflow.com/questions/39331241/a.jsp" class="group1">aa</a>
<a href="b.jsp" class="group2" >bb</a>
<a href="c.jsp" class="group1">cc</a>
<a href="d.jsp" class="group2">dd</a>
<a href="e.jsp" class="group1">ee</a>

//js
$('.group1').hide();

you can also add css in the jquery

//js
$('.group1').css('display','none');

but the better way of altering the display state is to have a class that you then add or remove to the elements – that way you are not altering the actual css of the element:

//css
.hidden {display:none}
.shown{display:block}

//js


$('.group1').addClass('hidden');

you can also toggle the class – which allows you to show the elements simply by not hiding them
//js

 $('.group1').toggleClass('hidden');

solved Can I use jquery to operate the name attribute of tag?