/    Sign up×
Community /Pin to ProfileBookmark

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:

[CODE]

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.

[/CODE]

Thank you so much! I seriously could use as much help as possible!

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@nathanielelliotauthorSep 22.2011 — I realized that I should of put the HTML as well, here is the HTML that I am working with.
[code=html]<a href="http://randomlyopen.com/i/gallery/img/04.jpg"><img id="image01" src="" alt="Title One1 Area" url="http://google.com" /></a>
<div class="block">
<h2><span id='title01Span'></span></h2>
<p><a href="http://www.google.com" target="_parent" style="color:white;">Moving Us forward one step at a time... Description Area</a>.</p>
</div>[/code]
Copy linkTweet thisAlerts:
@007JulienSep 23.2011 — 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 : [I]document.getElementById("hrf"+idx)[/I] to keep links with ids : [I]hrf0, href1[/I], ...

Then you change their property with myLink.href="the new link" or myImage.alt="the new alt".
×

Success!

Help @nathanielelliot spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.9,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...