0

I am trying js:

$('a[data-select="more-options"]').click(
  function () {
    $('select')
      .append($("<option></option>")
      .attr("one more additional and long option",3)
      .text("3333333333"));
  }
);

on HTML of

<span id="dropdown">A 
  <select>
    <option>this is option 1</option>
    <option>This is option 2</option>
  </select> list<br>
</span>

&nbsp;<a data-select="more-options" href="#">Add long option to the select</a>

but I get no results (or error).

2
  • 4
    "one more additional and long option" is it attribute ? Commented Jun 21, 2014 at 17:50
  • 3
    I do get an error when I execute the code in Chrome 35: Uncaught InvalidCharacterError: Failed to execute 'setAttribute' on 'Element': 'one more additional and long option' is not a valid attribute name. Commented Jun 21, 2014 at 17:52

2 Answers 2

2

Check this fiddle.

$('select').append( "<option>This is option 3</option>" );

This appends the third option to select. You can add other attributes to the option.

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

Comments

-1

Check this,

$('a[data-select="more-options"]').click(function () {
     $('select').append("<option>3333333333</option>");
});

jsfiddle

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.