javascript - jQuery - how to determine which link was clicked -
i have simple piece of php generates n copies of following code:
<p class="showsdb_l2" class="center" onclick="fsd_l2('<?php print dbg;?>','<?php print $slid;?>')">click here see data</p> <div class="divsdb_l2"> </div>
it generated using php, number of copies unknown front.
on page have following javascript (using jquery)
function fsd_l2(dbg,slid) { $(".divsdb_l2").load("test15.php?dbg="+dbg+"&slid="+slid).css('display','block'); }
when text above (click here see data) clicked, should add contents of test15.php between the 2 div tags.
#test15.php <?php $dbg = $_get['dbg']; $slid = $_get['slid']; print $dbg . " & " . $slid; ?>
the problem have how determine of links clicked? @ present, if have 3 copies, , click one, 3 copies activated.
i hope have made clear enough. i'm sure there must simple way, i'm quite new javascript/jquery.
am not sure understand having difficulty with, following how it.
<p class="showsdb_l2" class="center" data-dbg="<?php print dbg;?>" data-slid="<?php print $slid;?>">click here see data</p> <div class="divsdb_l2"></div> $(document).ready(function() { $(document).on('click', 'p.showsdb_l2', function(evt) { var $p = $(evt.currenttarget), dbg = $p.data('dbg'), slid = $p.data('slid'), $div = $p.next(); fsd_l2(dbg, slid, $div); }); }); function fsd_l2(dbg, slid, $div) { $div.load("test15.php?dbg="+dbg+"&slid="+slid).css('display','block'); }
the click handler not hardcoded each p
tag. instead each p
tag store required data, ie dbg
& slid
.
the click handler attached once @ document ready
. jquery abstracts on various browsers , passes handlers event
object first parameter. object can used find element on event occurred. refer: http://api.jquery.com/on/
finally, fetch required data clicked element, find div
needs updated , call custom function.
Comments
Post a Comment