views:

355

answers:

1

Hi guys

as the title suggests i have problem with prototype's update function in all IE version but its working in FF and chrome

this doesnt work

var element = $('mainnav_h');
element.cleanWhitespace();
var html = element.firstChild.innerHTML;
html = html.gsub('<span class="sep"></span>', '');
element.firstChild.update(html);//this doesn't word

but this works

var element = $('mainnav_h');
element.cleanWhitespace();
var html = element.firstChild.innerHTML;
html = html.gsub('<span class="sep"></span>', '');
element.firstChild.update("this works");

source

<div class="innerNavigation_horizontal clear">
    <ul id="mainnav_h">
        <li><span class="sep"></span><a href="#" title="#">items</a></li>
    </ul></div>

you can see clearly when i pass variable to update() function is doesn't work in IE where as when i pass string in to it it works in IE, can some one explain this absurd IE behaviour

salman

A: 

My guess is that the problem is not with update(), but with one of the preceding functions that work on the HTML.

Can you do a test output of html using alert() at every stage of the script? Does it contain anything in the first place?

What does #mainnav_h look like? Can you post source?

Does element.firstChild actually exist? Can you check using

alert(typeof element.firstChild);

Do you get any error messages in IE?

Pekka
alert(typeof element.firstChild); its an object and it does exist i just alert(html) and found out that gsub function is not working in IE, #mainnav_h is a ul id in list and its child are list items, all i want is to delete '<span class="sep"></span>' this from innerHTML of first child of ul im also posting source
Salman
I suspected `gsub` too. How about a simple `replace()` instead? http://www.w3schools.com/jsref/jsref_replace.asp Remember you need to submit your pattern as a regex (i.e. escape the special characters).
Pekka
replace( /<[^<]+?>\<\/span\>/g,''); i used regular expression and that did the trick as suggested, by the way i also noticed that IE and FF have different approach towards rendering HTML here is an exampleIE will display this ( <SPAN class=sep></SPAN> ) whereas FF will display ( <span class="sep"></span> ) note the class name wrapped in double quotes and whole html is in lowercase, one should care for these difference otherwise you regular expression can fail and you wont figure out why its working in FF and not IE and viceversa
Salman
That's basically why one shouldn't use regular expressions or replace operations for HTML in the first place. It would be cleaner to cut out the span using the DOM.
Pekka