html - Apply attr to div but not to children (JQuery) -
i have html code looking this:
<div id='main'> <a href=''> <div id='othera'> <a href=''> </div> <div id='otherb'> <a href=''> </div> </div> i apply attribute "target" elements of #main not of #other using jquery. tried few things , think closest got not seem work.
$(document).ready(function(){ $('#main a').not(['#othera a', '#otherb a']).attr('target', '_blank'); });
use #main > a selector. pick 'a' tags under #main.
$(document).ready(function(){ $('#main > a').attr('target', '_blank'); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> <div id='main'> <a href=''>main a</a> <div id='othera'> <a href=''>asdsf</a> </div> <div id='otherb'> <a href=''>kjklsdf</a> </div> </div>
Comments
Post a Comment