I am working with jQuery for the first time and need some help. I have an html that looks like this:
<div id='comment-8' class='comment'>
<p>Blah blah</p>
<div class='tools'></div>
</div>
<div id='comment-9' class='comment'>
<p>Blah blah something else</p>
<div class='tools'></div>
</div>
I am trying to use jQuery to add spacing to div.tools that call variouis functions when clicked. Functions must get the identifier (either the entire comment-8 or part "8") of the parent comment so that I can then show the form or other information about the comment.
What I have so far:
<script type='text/javascript'>
$(function() {
var actionSpan = $('<span>[Do Something]</span>');
actionSpan.bind('click', doSomething);
$('.tools').append(actionSpan);
});
function doSomething(commentId) { alert(commentId); }
</script>
I am fixated on how to populate the commentId parameter for doSomething. Perhaps, instead of id, I should pass a link to the passed interval. It may be fine, but I'm not sure how to do it.
Thanks Brian
source
share