Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 18th Dec 2016, 11:42 PM   #1
Sky Marshal
War Room Member
 
yangyang's Avatar
 
Join Date: 2007
Location: TheDataPlanet.com
Posts: 86
Thanks: 26
Thanked 4 Times in 4 Posts
Blog Entries: 1
Default
jQuery closest() remove() on <a> doesn't work?
Share on: 
fb share twitter share gplus share more share

Please see this page which has this code:

Code:
<div class="pure-control-group query-brand-by-column">
    <!-- somethings else -->
    <div class="pure-u-1 pure-u-sm-1-24 control-group-sub">
        <a href="javascript:$(this).closest('.query-brand-by-column').remove();" class="pure-button danger">X</a>
    </div>
</div>
Clicking the X link should remove its ancestor div.query-brand-by-column as a whole but somehow it's not working. I've checked jQuery docs and this answer and the code seems absolutely all right to me but it simply doesn't work. Any idea?

1. Global Movies Database = $489.95 = 1.5 GB data + 65.9 GB images.

2. World Hotels Database = $589.95 = 1.54 GB data + 71.4 GB images.

3. Auto Parts Database = $489.95 = 15.8 GB data + 30.4 GB images.
yangyang is offline  
Unread 19th Dec 2016, 12:29 PM   #2
Warrior Member
 
anuislam's Avatar
 
Join Date: 2015
Location: Bangladesh
Posts: 13
Thanks: 1
Thanked 1 Time in 1 Post
Default
Re: jQuery closest() remove() on <a> doesn't work?
Share on: 
fb share twitter share gplus share more share

Please see this following instruction i hope it's very helpful for you.

Thank you

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
</head>
<body>
<div class="pure-control-group query-brand-by-column">
<!-- somethings else -->
<div class="pure-u-1 pure-u-sm-1-24 control-group-sub">
<a href="#" id="your_id_name" class="pure-button danger">X</a>
</div>
<script>
$(document).ready(function(){
$('#your_id_name').on('click', function(e){
e.preventDefault();
$(this).closest('.query-brand-by-column').remove();
});
});
</script>
</div>
</body>
</html>
anuislam is offline  
Unread 5th Jan 2017, 01:38 PM   #3
Active Warrior
 
Join Date: 2013
Posts: 31
Thanks: 3
Thanked 8 Times in 6 Posts
Default
Re: jQuery closest() remove() on <a> doesn't work?
Share on: 
fb share twitter share gplus share more share

anuislam has it right. You should do your JS in a script tag seperate from your link. Jquery makes it so easy with css selectors too.

shaneburgess is offline  
Closed Thread


Bookmarks

Tags
&lta&gt, <a>, closest, jquery, remove, work


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 09:53 AM.