I have HTML like this:
<div id="signbtn">
<a class="btnsignin" href="signin.php">Admin</a>
</div>
How do I find the class of the anchor tag embedd开发者_JAVA百科ed inside the div
with id="signbtn"
.
I need this to be able to assign a different class to the anchor tag only if has "btnsignin"
class.
You could use the .attr()
function:
var class = $('#signbtn a').attr('class');
and to assign a different class to an anchor with the btnsignin
class inside an element with id="signbtn"
:
$('#signbtn a.btnsignin').attr('class', 'some_new_class');
i think should do the trick for you
$('#signbtn').click(function() {
$.each($(this).children('a'), function(){
if($(this).hasClass('btnsignin')){
$(this).attr('class', 'anotherclass');
}
})
});
also you can change the $(this).attr('class', 'anotherclass');
to
$(this).addClass('anotherclass');
for add multiple classes to the field
精彩评论