jquery - How to find out if a tag has a specific class AND id -
have body tag on page has both id , class:
<body class="class" id="id">
i'm trying use jquery chance content further down page, based on class , id are. i've had no success, it's worth, here's tried do:
if($('body').is('#id1')){ if($(this).hasclass('class1')){ $('ul.nav li.first').html('<h2>special title</h2>'); }else if($(this).hasclass('class2')){ $('ul.nav li.first').html('<h2>other title</h2>'); } }else if($('body').is('#id2')){ if($(this).hasclass('class1')){ $('ul.nav li.first').html('<h2>special header</h2>'); }else if($(this).hasclass('class2')){ $('ul.nav li.first').html('<h2>other title</h2>'); } }
anyone have quick way of doing this? i'm terrible @ "if" looping using jquery, have been.
cheers,
t
for record there no need use jquery here.
var isid = (document.body.id === someid); var isclass = (document.body.classname.indexof(someclass) !== -1); if (isid && isclass) { // }
[edit]
the class check horrible. try
var regexp = new regexp("(^|//s)" + someclass + "($|//s)", "m"); var isclass = (document.body.classname.search(regexp) !== -1);
Comments
Post a Comment