jquery - how to select specific <span> under <div> -
i have structure similar to,
<div class="div1"> <a class="myimg" href="#">clickme1</a> <span>myspan1</span> </div> <div class="div2"> <a class="myimg" href="#">clickme1</a> <span>myspan2</span> </div>
css
<style type="text/css"> .div1 { border: 1px solid red; } .div2 { border: 1px solid black; } .test { border: 1px solid yellow; } </style> <script type="text/javascript"> $(function () { $("a.myimg").click(function () { alert($(this).html()); $("span").addclass("test"); }); });
now when click on <a>
span in both divs getting affected, want if click on div1 <a>
should affect span1, , same div 2. how achive in jquery.
</script>
edit: possible using context, similar to,
$("a.myimg",context).click(function () {
change code specify span want modify (the 1 next image) .next("span")
...
$(function () { $("a.myimg").click(function () { alert($(this).html()); $(this).next("span").addclass("test"); }); });
Comments
Post a Comment