jQuery: Checking to see if list contains text, then redirect, else redirect here -
i'm complete novice when comes jquery, please bear me...
i have html
<ul class="zonesubscriptions"> <li> <ul> <li class="zonename"><a href="/default.aspx?pageid=8267303">my account</a></li> <li>never</li> </ul> </li> <li> <ul> <li class="zonename"><a href="/default.aspx?pageid=8269026">practitioners area</a></li> <li>never</li> </ul> </li> </ul>
if link practitioners area present, redirect browser href, else, redirect account section.
this jquery have...
jquery.noconflict(); jquery(document).ready(function() { if(jquery(".zonename a").text() == 'practitioners area'){ document.location.href = $(this).attr('href'); }else{ document.location.href = jquery('.zonename:first a').attr('href'); }; });
when runs, redirects me account, though practioners area present.
i know i'm doing stupid... can me , show me light? appreciated! thanks!
change condition in if
statement this:
$(".zonename a:contains('practitioners area')").length
the problem attempt jquery(".zonename a").text()
return text of matched elements (in case, returns "my accountpractioners area"). version checks see if there matching elements containing string "practioners area". here's full code:
jquery(document).ready(function() { if($(".zonename a:contains('practitioners area')").length) { document.location.href = $(this).attr('href'); }else{ document.location.href = jquery('.zonename:first a').attr('href'); }; });
Comments
Post a Comment