Click event gets fired multiple times
Hi,
I have following htnl code
- <div id="divTag1">
- <div class="singletagblock" >
- <a href="/Tagging/BrowseTag" id="tagname">tag for details page</a>
- <a href="" class="removetag" id="removeTag1"></a>
- </div>
- <div id="addtag1" style="display:inline-block">
- <a href="#" >+Add tag</a></div>
- <div id="divAddTagBox1">
- <input id="txtTag1" name="tags" type="text" value="" />
- <input type="button" value="Add" id="btnAddTag1"/>
- <input type="button" value="Cancel" id="btnCancelTag1" />
- </div>
- </div>
and following is jquery to do some server side stuff
- $(".removetag").click(function (event) {
-
- var tagtext = $(this).prev().attr('text');
- var parentdiv = $(this).parent();
- alert(tagtext);
- $.ajax({
- url: "/Tagging/RemoveTag",
- datatype: "json",
- type: "POST",
- data: { "tag": tagtext,
- "entityId": "1",
- "entityType": "2"
- },
- success: function () {
- parentdiv.remove();
- },
- error: function (xhr, ajaxOptions, thrownError) {
- alert(thrownError);
- }
- });
- return false;
- });
I used above html code multiple times on single page.
Now when I click on .removetag link the click event gets fired multiple times for all the links with class removetag. How to prevent this?
Thanks