I'm creating a sitemap function for my website what I have a function which appends a new select box which multiple options and I have a remove function which will remove the select box.
Well I say remove the select box but what it actually does is remove all the select boxes that were created, however I wanted it to target the select box that it is related to.
I believe one way to implement this is to assign a different class to the select box element, does anyone know how I can do this?
Or can anyone recommend a better way to handle this?
The code I have so far is below, or view my jsFiddle
$("#newsublevel").click(function() {
$(".navoptions").append('<br/><select class="newoption"><option value="Home">Home</option><option value="Home">Home</option><option value="Home">Home</option><option value="Home">Home</option><option value="Home">Home</option></select><a href="#" class="remove">Remove</a>');
});
$(".navoptions").on('click','.remove',function() {
$(".newoption, .remove").remove();
});
add.html
<div class="maincontent">
<h2 class="sitemaphead">Sitemap</h2>
<p>Add a sub level to About.</p>
<div class="navoptions">
<select>
<option value-"Home">Home</option>
<option value-"Home">Home</option>
<option value-"Home">Home</option>
<option value-"Home">Home</option>
<option value-"Home">Home</option>
<option value-"Home">Home</option>
<option value-"Home">Home</option>
</select>
</div>
<p id=""><a href="#" id="newsublevel">Click here</a> to add another sub level</p>
</div>