473,395 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to chage images within a tags range?

Hi,

I'm currently trying to create a very particular rollover effect.
I need to programmatically modify a number of images.

A short example of the current html, which I'm trying to modify.

Expand|Select|Wrap|Line Numbers
  1. <a href="temp.html"onMouseOver="mouseover(this);"><span class="p1CE"><img src="1.png"></span><span class="p1CB"><img src="1.png"></span></a>
  2.  
In this example there are only 2 SPANs but there could be many more.

When the mouseover event is triggered, the mouseover function receives the link object. I can use this to go through the SPAN's using childNodes. However I cant figure out how to rewrite the SPANs content!

All I need to do is modify each
Expand|Select|Wrap|Line Numbers
  1. <img src="1.png">
to
Expand|Select|Wrap|Line Numbers
  1. <img src="1hl.png">
.

There is only ever 1 IMG inside a SPAN.

Any help would be greatly appreciated.
Thanks

PS. If I have missed the obvious its because this is my second day learning JavaScript so apologies in advance.
Mar 5 '08 #1
4 930
gits
5,390 Expert Mod 4TB
hi ...

let me give you an idea :)

Expand|Select|Wrap|Line Numbers
  1. // retrieve the src from the image node
  2. var s = img_node.src;
  3.  
  4. // now we match the chars before the .
  5. var m = s.match(/([^\.])/)[1];
  6.  
  7. // next we replace it like this 
  8. var src = s.replace(m, m + 'h1');
  9.  
  10. // now we set the src of the image node
  11. img_node.src = src;
  12.  
kind regards
Mar 5 '08 #2
Thanks gits for your post. To use your example I assume I need access to the image nodes. The problem I have is that I cannot figure out how to get to the image nodes using the DOM!

My current (non-working function!) is as follows.

Expand|Select|Wrap|Line Numbers
  1. function mouseover(obj)
  2. {
  3.     for(i=0; i<obj.childNodes.length; i++)
  4.     {
  5.        obj.childNodes[i].innerHTML = "<img src="1hl.png">";
  6.     }
  7. }
  8.  
Mar 5 '08 #3
Oops,
Just got it working, I was using the wrong quotes!
Sorry and thanks for the help.
Mar 5 '08 #4
gits
5,390 Expert Mod 4TB
hi ...

glad to hear you got it working :) ... post back to the forum anytime you have more questions ...

kind regards
Mar 5 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Donald Firesmith | last post by:
Are html tags allowed within meta tags? Specifically, if I have html tags within a <definition> tag within XML, can I use the definition as the content within the <meta content="description> tag? ...
3
by: stan k. | last post by:
First of all let me clarify - I am not talking about having a bunch of images loaded all at once (or preloaded) and then controlling the display of the images after that point -- I know that can be...
8
by: George Adams | last post by:
I'm just starting to pick up some CSS knowledge after about 10 years of plain ol' HTML coding. I'm finding it easiest to learn CSS by example, so I'm following with interest the tricks I see done...
61
by: phil-news-nospam | last post by:
Why does SVG need a different tag than other images? IMHO, SVG should be implemented as an image type just like any other image type, allowing it to work with <img> tags, and ... here is the...
1
by: nwebhosting | last post by:
Hello and thank you. Could you please help me with this.: i try to store images using the following code, and it just bring a blank screen. i being trying different things and i am not sure if...
5
by: royend | last post by:
Is it possible to hide images from the internet, and only have a image available for users that are logged into the intranet? I am hoping to avoid a database-solution as the number of images will...
2
by: gunnuk | last post by:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta...
5
by: rosaryshop | last post by:
I'm working a jewelry/rosary design web site at http://www.rosaryshop.com/rosariesAndKits2.php. As the user makes selections, it updates images of various parts, giving them a preview of the...
4
by: harryusa | last post by:
I am trying to center 2 images concentrically which are z-indexed to lay on top of each other making an image with a border from another image that has a transparent center. I need the images to be...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.