I am attempting to call the remove()
jQuery function on a div
tag which has been added after the page is loaded. I am adding this div
link this:
$(probablyHide).html(addedDiv);
<div class=probablyHide>
<div onClick="myMethod(this)" class="hide" id="1">i want to hide this div 1</div>
<div onClick="myMethod(this)" class="hide" id="2">i want to hide this div 2</div>
<div onClick="myMethod(this)" class="hide" id="3">i want to hide this div 3</div>
</div>
However for some reason my remove()
is not working properly.
function myMethod(div)
{
var button = $(div).closest('div.otherDiv').find("select[id^='stuff']");
button.val(div.id);
$(div).remove();
$(button).trigger('change');
};
What is weird is if I edit out the following lines in my function. The div will be deleted.
button.val(div.id);
$(button).trigger('change');