Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i have button on my form to create textarea
i made add textarea dynamically and i add id to it by counter like this
JavaScript
id="createdTextBox' + count +


and i have button to delete this textarea if selected
but i can't get element id to remove selected element

i write
JavaScript
$("#" + selectedObject).remove();

but it don't work as i don't have id

how can i get id for selected element?
Posted
Comments
Mohibur Rashid 25-Jun-14 17:58pm    
you can just
$(selectedObject).remove();

besides if you don't know id you get get id by
$(selectedObject).attr('id')
Heba Kamel 26-Jun-14 13:13pm    
Thanks Mohibur it's run :)
add solution to i can accept it
Mohibur Rashid 26-Jun-14 20:27pm    
Don't worry about accepting answer. Just happy to help
DamithSL 26-Jun-14 22:06pm    
it is not only about thanking by accepting answer. this question is listed on unanswered question list even though it is solved by your comment.
you are helping to save some time of other code project user who spend time on answering to unanswered questions and also accepted answer help someone else having same issue rather than reading all other answers and comments.
Mohibur Rashid 27-Jun-14 0:44am    
alright.

As OP requested, the tip is copied to answer box so that he can accept
you can just
JavaScript
$(selectedObject).remove();


besides if you don't know id you get get id by
JavaScript
$(selectedObject).attr('id')
 
Share this answer
 
v2
Comments
DamithSL 27-Jun-14 0:47am    
my 5!
Mohibur Rashid 27-Jun-14 1:08am    
Thank you
check below examples fro how you can add remove dynamic text boxes on button click
Dynamically Add and Remove HTML Elements using JQuery append(), after() and remove() methods[^]
JQuery to create dynamic textboxes on button click[^]
hope this helps you to find solution.
 
Share this answer
 
Hi,

Declare count Variable globally,
when click remove button you can get count of newly created control.
 
Share this answer
 
Comments
Heba Kamel 26-Jun-14 12:38pm    
i don't want remove newly element i want remove selected element

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900