Reputation: 2441
i'm trying to remove a div based on the id and class but when executing i can only remove it by using an individual value from either the id or class but not both.
EX:
<div id="69" class="form-loader">
test 69
</div>
<div id="70" class="form-loader">
test 70
</div>
<input type="text" value="69" id="loader-form-val"/>
<button class="form-delete-con">click</button>
$('.form-delete-con').live("click",function() {
var del = $('#loader-form-val').val();
$('#'+del+' .form-loader').remove();
});
Upvotes: 0
Views: 1442
Reputation: 59769
It's the extra white space in the string containing the class name, .form-loader
$('.form-delete-con').live("click",function() {
var del = $('#loader-form-val').val();
$( '#' + del + '.form-loader').remove();
}); // ^ you had ' .form-loader'
Upvotes: 1
Reputation: 206008
ID
s are unique therefore you don't need to bother with any class
things
Also from jQuery v.1.7
the .live()
method is deprecated and it's substituted with .on()
This will do the job:
$(document).on("click", '.form-delete-con', function() {
var del = $('#loader-form-val').val();
$("#"+ del).remove();
});
Upvotes: 0