Change an image "src" / "url" / "alt" separately!
I am trying to manipulate a an image gallery that functions well. Now, I have the ability to pull information from a user's preference pannel and need to place it in the an href="" // And other information in each of the "src" | "url" | "alt".
Any ideas would be truly helpful. This is what I am working with at the moment and it doesn't work (obviously because it is adding code inside a span). Here is what I am starting from:
Thank you so much! I seriously could use as much help as possible!
var title01Span = document.getElementById('title01Span'), //Finds the id that I want
prefs = new gadgets.Prefs(), // Pulls from the user's preferences
yourtitle01 = prefs.getString("title01"); // Pulls the correct string from those preferences
title01Span.innerHTML = yourtitle01; // replaces the span.id with that text but I need to be able to do this in the src / href / url / etc.
I realized that I should of put the HTML as well, here is the HTML that I am working with.
<a href="http://randomlyopen.com/i/gallery/img/04.jpg"><img id="image01" src="" alt="Title One1 Area" url="http://google.com" /></a>
<p><a href="http://www.google.com" target="_parent" style="color:white;">Moving Us forward one step at a time... Description Area</a>.</p>
You can walk thougth the DOM tree like explain on this page.
But be careful the nodes trees are not the same in all browsers. Some browsers adds nodes (with type!=1) with carriage return in HTML. Then getElementsByTagName and getElementById are probably the best choice to kept your objects...
You can always build id dynamically with forms like : document.getElementById("hrf"+idx) to keep links with ids : hrf0, href1, ...
Then you change their property with myLink.href="the new link" or myImage.alt="the new alt".
Last edited by 007Julien; 09-23-2011 at 05:33 AM.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread