when click on 1 of buttons, <p>s in encapsulating div should given yellow background.
ideally see $(this), parent , matching elements selector in jquery selector. update: sorry did not make request clear.
see selectors of parent div, elements select in parent , $(this) in select clause.
want <p> elements .left div, can extend selector clause this
$("p", ".left") - gets <p> in .left
in case, hold of .left using $(this), while "is" button. should in lines of
$("p", $(this).closest("body > div"))
heres jsfiddle
code.
<style> div p.painted { background-color: #ff0; } </style> <div class="left"> <div class="actions"> <div class="ui"> <div class="colors"> <button class="paint">paint yellow!</button> </div> </div> </div> <p> lorem ipsum </p> <p> lorem ipsum dummy text of printing , typesetting industry. lorem ipsum has been industry's standard dummy text ever since 1500s, when unknown printer took galley of type , scrambled make type specimen book. has survived not 5 centuries, leap electronic typesetting, remaining unchanged. popularised in 1960s release of letraset sheets containing lorem ipsum passages, , more desktop publishing software aldus pagemaker including versions of lorem ipsum. </p> </div> <div class="right"> <div class="actions"> <div class="ui"> <div class="colors"> <button class="paint">paint yellow!</button> </div> </div> </div> <p> lorem ipsum </p> <p> lorem ipsum dummy text of printing , typesetting industry. lorem ipsum has been industry's standard dummy text ever since 1500s, when unknown printer took galley of type , scrambled make type specimen book. has survived not 5 centuries, leap electronic typesetting, remaining unchanged. popularised in 1960s release of letraset sheets containing lorem ipsum passages, , more desktop publishing software aldus pagemaker including versions of lorem ipsum. </p> </div> <script> $(function(){ $(".paint").click(paintit); }); function paintit(){ $(this).closest("p").addclass("painted"); } </script>
you can use siblings() instead of closest select <p>s. here's updated fiddle.
Comments
Post a Comment