Reputation: 39
I have a function that appends some html on the fly to a container div. I want to be able to tap on this created html and make it go away, but cant seem to get it to work.
So for example if i have this function created from a tap on another element:
function functionName(e){
$('<div />').attr({id: 'someid '}).text(' Text Text Text').appendTo('.container');
}
I want to be able to then remove it like this:
$('someid').tap(function(){
$(this).remove();
}
Any idea how to make this work?
Upvotes: 2
Views: 3509
Reputation: 1882
It should be OK if you use click() method
$('#someid').click(function(){
$(this).remove();
});
There's no problem with Android browser.
Upvotes: 1
Reputation: 9661
You haven't added the #
to the selector to add the touch event to the someid
element, as well as your ending );
...
$('#someid').tap(function(){ ... });
You might also need to use something like the .live()
function to 'on-the-fly' add the tap event handler to any elements that are added dynamically to the page's content. Something like:
$('#someid').live('tap', function(){ ... });
Upvotes: 4