views:

26

answers:

1

Hi Guys,

I have the following HTML

<div id="top-right">
<span id="top-right-name">sometexthere</span> | <a href="#">link</a>
</div>

And the following prototype JS

   Event.observe(window, 'load', function() {
try { 
if ($$('#top-right')!=null) {

var topmenu = document.getElementById('top-right');
var value = topmenu.innerHTML;
// define an array of replacements
var replacements = [
    { from: '|', to: ' ' },
    { from: '|', to: ' ' },
    { from: '|', to: ' ' },
    { from: '|', to: ' ' }
];
for (var i = 0, replacement; i < replacements.length, replacement = replacements[i]; i++) {
    // replace
    value = value.replace(replacement.from, replacement.to);
}
// replace the old text with the new
topmenu.innerHTML = value;  

}
} 
catch(ex) {
}
});

I am trying to remove the " | " after the </span> automatically onload of the this JS - but I just cant seem to do it .

Can someone assist ?

Thanks

A: 

It seems to be a syntax error somewhere, perhaps in your loading of Prototype. The below snippet worked fine for me :)

<script type="text/javascript" 
    src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js"&gt;&lt;/script&gt;

<div id="top-right">
<span id="top-right-name">sometexthere</span> | <a href="#">link</a>
</div>

<script type="text/javascript">
Event.observe(window, 'load', function() {
try { 
if ($$('#top-right')!=null) {

var topmenu = document.getElementById('top-right');
var value = topmenu.innerHTML;
// define an array of replacements
var replacements = [
    { from: '|', to: ' ' }
];
for (var i = 0, replacement; i < replacements.length, replacement = replacements[i]; i++) {
    // replace
    value = value.replace(replacement.from, replacement.to);
}
// replace the old text with the new
topmenu.innerHTML = value;  

}
} 
catch(ex) {
}
});
</script>

Edited to reflect problem

KennyCason
hi kenny - thanks for the help but I'm use the Prototype library - not jQuery - hence the syntax $$ :)
Tom
Oh crap. Sorry I didn't notice that!is the Event.observe(window, 'load', function() {}) at least being called? Other than that your syntax seems fine to me! :)
KennyCason
cheers thx - was the load prob :)
Tom
nice, glad you figured it out :)
KennyCason
I will update the Answer to reflect that if you could vote it up. Thanks!
KennyCason