View Full Version : Remove span tags

04-07-2009, 11:12 AM

Basically I have a button which when clicked creates a set of span tags around highlighted text. (as shown below).
onMouseOver should call a function RemoveTags(event) which should remove these tags? How can i do this?

<span onMouseOver = "this.style.color = 'Red'; RemoveTags(this)" > the dog and the cat</span>

kind regards


04-07-2009, 03:37 PM
It is not clear what you are actually doing here. Could we see the code that selects the text? I presume that this code adds the span tags and inserts the onmouseover text as well. Why do you want to remove the span tags? If you mouseover and the colour changes, then it will stay changed. Do you have code for RemoveTags? If so could we see it.

If you remove the <span> tags, then the span element you are styling will no longer exist, and I would not like to predict what (if anything) the browser DOM would make of it.


04-07-2009, 06:09 PM
with reference to "Could we see the code that selects the text?" :

Couldn't I use "this" passed through "Removetags(this) ?

I tried somehting like this:


but it removes everything including the text. I want the text to remain.



04-07-2009, 09:56 PM
chris, I showed you the method.
here's the link
run this script. Firefox only, sorry it needs the IE tuning, but I had to resolve an issue with the removed elements interupting the next selections.
Click on the box to start.
it puts an a span with the index number and a starting image in front of the selection and it piuts and image at the end of the slection.... then 2 seconds later the script takes them back out!! It's exactly what you want to know! View the page source, or save the page.

04-08-2009, 12:57 AM
Thanks again Tinyscript for all your help.

For anyone interested check this:


thanks once again