0

Consider the following HTML :

<div class="list">
<select>
    <option value="one">1</option>
    <option value="two">2</option>
</select>

And Javascript :

  var s_m = $("select option[value='one']");
  var sec_mark = s_m.clone();
  console.log(sec_mark.html());

I obtained simply 1 text as a result. How can get full option html like <option value="one">1</option>?

Luciuz
  • 1,637
  • 5
  • 14
  • 15

1 Answers1

1

You need to do something like this -

var s = s_m.clone().wrap('<select></select>').parent().html();

That should get the full outer html of the option element, there are further techniques explained in this question - Get selected element's outer HTML

Community
  • 1
  • 1
ipr101
  • 24,096
  • 8
  • 59
  • 61