Reputation: 2261
Hi i am trying to remove an item that is hyperlinked with Jquery and it doesn't seem to be working out that good, can someone shed a little light? Thanks.
HTML Code:
<ul id="displayAgency">
<li><a href="#" agencyId="809" class="itemDelete">Item One</a>
</li>
<li><a href="#" agencyId="209" class="itemDelete">Item Two</a>
</li>
<li><a href="#" agencyId="409" class="itemDelete">Item Three</a>
</li>
<li><a href="#" agencyId="709" class="itemDelete">Item Four</a>
</li>
</ul>
Jquery:
$('#displayAgency').click('click', function () {
$("li itemDelete").remove();
return false;
});
Upvotes: 0
Views: 67
Reputation: 33870
You are missing the class selector :
$("li .itemDelete").remove(); //Which is a dot
You might wanna note that this will delete all li
no matter which one you click and go back to the top of the page.
Are you looking for this instead?
$('#displayAgency .itemDelete').on('click', function (e) {
$(this).remove(); //This remove the 'a' but keep the 'li'
//$(this).parent().remove(); would remove the 'li'
//return false; You should use prevent default
e.preventDefault();
});
Upvotes: 4