when i...">

InnerHTML replace does not reflect

I have HTML something like this

<div id="foo">
<select>
<option> one </option>
</select>
</div>

when i use

document.getElementById('foo').innerHTML = document.getElementById('foo').innerHTML.replace("<option> one </option>", "<option> two </option>") ;

innerHTML is replaced but not displayed in the browser.

If I warn innerHTML, I see that it has been changed now, but in the browser it still shows the old version.

Is there a way to make this change a recognized browser?

Thanks in advance.

+5
source share
7 answers

works great for me in firefox 3.5

Working demo

EDIT: You must use IE. You need to create a new option and add it to an element or change the text of an existing option

- FireFox IE 7.

var foo = document.getElementById('foo');
var select = foo.getElementsByTagName('select');
select[0].options[0].text = ' two ';
+7

select .

var sel =document.getElementById ( "selectElementID" );
var elOptNew = document.createElement('option');
elOptNew.text = 'Insert' + 2;
elOptNew.value = 'insert' + 2;
sel.options.add ( elOptNew );

sel.options[indexNumber].text = 'text_to_assign';
sel.options[indexNumber].value = 'value_to_assign';
+3

innerHTML IE. , 7 8. , , , , . outerHTML, . outerHTML IE ( ), select.parentNode.innerHTML. . innerHTML div, . FYI.

, , replace . , . IE . innerHTML, , , . . , . , , 100%.

, , DOM ( ) . , . , DOM.

+3

, IE? , (...) SELECT IE. :

document.getElementsByTagName('select')[0].options[0]=new Option(' two ');

: Microsoft : http://support.microsoft.com/kb/276228

+2

, ,

strHTML = "&nbsp;<option value=""1"">Text1</option>"
strHTML = strHTML + "<option value=""15"">Text2</option>"
strHTML = strHTML + "<option value=""17"">Text3</option>"


document.getElementById("id-selectbox").innerHTML=strHTML;
if(Browser=="Internet Explorer"){
    document.getElementById("id-selectbox").outerHTML=document.getElementById("id-selectbox").outerHTML;
}

HTML AJAX.

/ selectbox .

: & nbsp , select- innerHTML

+1

You use replaceone that requires RegEx as the first argument.

Try the following:

document.getElementById('foo').innerHTML = document.getElementById('foo').innerHTML.replace(/<option> one <\/option>/, "<option> two </option>");

Does this work for you?

0
source

check this

document.getElementById('foo').innerHTML.replace("<option> one </option>", "<option> two </option>") ;

if it does not work, change the browser.

0
source

All Articles