I want to load a particular link when user press link.
jQuery:
<body>
...
<script type="text/javascript">
jQuery(".likeThis").click(function() {
jQuery(this).closest("a").load('{$likeThiSID}', function() {
});
});
</script>
HTML:
<span id="like"><a class="likeThis">Like This</a>
I am using CMS and that HTML code is echoed in a while where there will be around 10 entries.
Right now jQuery is working but it’s loading 10 times. How do I get which one of the link is clicked?
You can try it like this:
It only binds the click to elements that does’nt have a class “bound”. As after binding the elements will receive this class, they’ll not be affected later.
Another way may be gone with different markup :
(assuming that {$likeThiSID} will be replaced with a URL)
By that you dont need the script-part inside the loop, you’ll only need
…once inside the document.