javascript - How do I click a button and have it remove two things without knowing their ID or class values? -


the 2 things i'm talking text field , string represents html need type text field appear. there's button makes 2 things appear. each time button clicked, pair of same kind appears.

but, each time new pair generated, have button generated next text field upon being clicked supposed delete text field , string created it. so, how accomplish this?

program in "when button class x1 clicked, remove text field , string have class x1" , "when button class x2 clicked, remove text field , string have class x2", , on, mean solution besides that.

here's creation of text field/html pair looks like:

$(document).ready(function() { $('#textfield').click(function() { $('#codebox').append('<div id="divtext'+vistext+'"><input type="text" class="textfield" maxlength="0" id="vistext'+vistext+'"><input type="button" value="o" id="o"> <input type="button" value="?" id="que"> <input type="button" value="x" id="closex"><div id="textcode" class="codedisplay"><div class="textcode">&lt;div&gt;&lt;input&nbsp;type="text"&nbsp;class="textfield"&nbsp;id="text'+textclicked+'"&lt;/div&gt;&lt;br&gt;</div></div>');  $('#codebox2').append('&lt;div&gt;&lt;input&nbsp;type="text"&nbsp;class="textfield"&nbsp;id="text'+textclicked+'"&lt;/div&gt;&lt;br&gt;') 

if create elements dynamically, must have reference them code creates them. when creating button, add click listener uses these references via closure:

var text = document.createtextnode("some text"); var input = document.createelement("input"); var button = document.createelement("button"); button.addeventlistener("click", function() {   text.parentelement.removechild(text);   input.parentelement.removechild(input);   button.parentelement.removechild(button); }); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -