16

When I attempt to add an option to a select, the option I’m trying to append ends up appended to the first option instead of the select itself.

$(".ct [value='']").each(function() { $(this).append($("<option></option>").attr("value", "Reset").text("Reset")); }); 

Help?

2

2 Answers 2

7

I'd have to see the HTML you're targetting to be sure, but it looks to me like your selector is targetting the first option of the select.

Try $(this).parent.append() instead.

Sign up to request clarification or add additional context in comments.

Comments

1
 $(this).parent().append($("<option></option>").attr("value", "Reset").text("Reset")); 

1 Comment

But this adds options equal to the number of empty valued options. So better change the selector.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.