regex - jQuery add class to href for target _blank -
i'd dynamically add class="external-link"
hrefs target="_blank"
excluding hrefs surrounding <img>
tag.
e.g.
<a href="#" target="_blank" >test</a> // i'd add class="external_link" <a href="#" target="_blank" ><img src="#" /></a> // nope, no class here thanks.
i assume regex can't figure out how exclude <img>
tags.
thanks.
a more general way, can apply tag, using jquery function $obj.children() $obj.children().length tells if there tag or not.
$('a[target="_blank"]').addclass(function(){ if($(this).children().length==0) return 'external_link'; })
check sample here: http://jsfiddle.net/pwru7/
Comments
Post a Comment