<div class="hidden" id="build_blankrow">
<span class="track_title"></span>
<span class="track_time"></span>
<span class="track_artist"></span>
<span class="track_album"></span>
<span class="track_number"></span>
<span class="track_options">
<span class="track_options_download"></span>
<span class="track_options_addtoplaylist"></span>
<span class="track_options_playnow"></span>
</span>
</div>
This is a hidden DOM element used to render a results page for a search (AJAX). I clone(true) the above elements and append it to the page, after updating and filling in the valid information. The problem stems from the fact the elements within the class “track_options” should behave in alternate ways. I see other questions on StackOverflow that remove behavior completely by preventing the default action (will link at the end of this post) but I want to remove the onClick event inherited from the parent and add an action specific to each element.
Still new to StackOverflow, so please feel free to ask any questions you feel would be beneficial.
Thank you everyone for even a pointer in the right direction!
unbind onclick event for 'a' inside a div with onclick event
You’re quest is a little confusing, but I’ll try to give a complete break down of just a few of the many ways to achieve your goal.
If you are trying to create a click for the parent Div that is not triggered by specific children then you can simple use event.stopPropagation() as so:
You may not want that stop prop on all children of track_options, thus you make use of .filter(). This handy jQuery func will allow you to stop prop on exactly the inner elements of track_options you choose. See example below:
You could make use of CSS selectors in jQuery to come up with clever ways to reach each element as desired. Something like:
Important jQuery Links used in previous code:
Something else that maybe of interest (and I’d show example except I have to go deal with a 4 year old not wanting to eat! grrr) is .andSelf(). It will allow to make a call to get track_options and 1 or 2 of its children like so:
$(".track_options).find("span:not(.track_options_addtoplaylist)").andSelf();