Skip to main content
edited tags
Link
kukkuz
  • 42.5k
  • 6
  • 65
  • 103
added 114 characters in body
Source Link
Fariz Luqman
  • 914
  • 5
  • 16
  • 27

Let say I have this variable html which contain these select options:

var html = '<select>'+ '<option value="10">10</option>'+ '<option value="20">20</option>'+ '</select>'; 

How can I programmatically select an option which is inside the html variable so when I append them to somewhere, for example

$('#select_handle'this).children('div').append(html); 

it will become like this:

<div<div> id="select_handle"><!-- children div of the current scope --> <select> <option value="10" selected>10</option> <option value="20">20</option> </select> </div> 

How is it possible?


edit: the variable contents is generated from remote locations, and I must change the value locally before it is being appended into a div. Hence, the question.

edit 2: sorry for the confusion, question has been updated with my real situation.

Let say I have this variable html which contain these select options:

var html = '<select>'+ '<option value="10">10</option>'+ '<option value="20">20</option>'+ '</select>'; 

How can I programmatically select an option which is inside the html variable so when I append them to somewhere, for example

$('#select_handle').append(html); 

it will become like this:

<div id="select_handle"> <select> <option value="10" selected>10</option> <option value="20">20</option> </select> </div> 

How is it possible?


edit: the variable contents is generated from remote locations, and I must change the value locally before it is being appended into a div. Hence, the question.

Let say I have this variable html which contain these select options:

var html = '<select>'+ '<option value="10">10</option>'+ '<option value="20">20</option>'+ '</select>'; 

How can I programmatically select an option which is inside the html variable so when I append them to somewhere, for example

$(this).children('div').append(html); 

it will become like this:

<div> <!-- children div of the current scope --> <select> <option value="10" selected>10</option> <option value="20">20</option> </select> </div> 

How is it possible?


edit: the variable contents is generated from remote locations, and I must change the value locally before it is being appended into a div. Hence, the question.

edit 2: sorry for the confusion, question has been updated with my real situation.

added 171 characters in body
Source Link
Fariz Luqman
  • 914
  • 5
  • 16
  • 27

Let say I have this variable html which contain these select options:

var html = '<select>'+ '<option value="10">10</option>'+ '<option value="20">20</option>'+ '</select>'; 

How can I programmatically select an option which is inside the html variable so when I append them to somewhere, for example

$('#select_handle').append(html); 

it will become like this:

<div id="select_handle"> <select> <option value="10" selected>10</option> <option value="20">20</option> </select> </div> 

How is it possible?


edit: the variable contents is generated from remote locations, and I must change the value locally before it is being appended into a div. Hence, the question.

Let say I have this variable html which contain these select options:

var html = '<select>'+ '<option value="10">10</option>'+ '<option value="20">20</option>'+ '</select>'; 

How can I programmatically select an option which is inside the html variable so when I append them to somewhere, for example

$('#select_handle').append(html); 

it will become like this:

<div id="select_handle"> <select> <option value="10" selected>10</option> <option value="20">20</option> </select> </div> 

How is it possible?

Let say I have this variable html which contain these select options:

var html = '<select>'+ '<option value="10">10</option>'+ '<option value="20">20</option>'+ '</select>'; 

How can I programmatically select an option which is inside the html variable so when I append them to somewhere, for example

$('#select_handle').append(html); 

it will become like this:

<div id="select_handle"> <select> <option value="10" selected>10</option> <option value="20">20</option> </select> </div> 

How is it possible?


edit: the variable contents is generated from remote locations, and I must change the value locally before it is being appended into a div. Hence, the question.

Source Link
Fariz Luqman
  • 914
  • 5
  • 16
  • 27
Loading