www.webdeveloper.com
Results 1 to 3 of 3

Thread: Change an image "src" / "url" / "alt" separately!

  1. #1
    Join Date
    Sep 2011
    Posts
    2

    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.
    Thank you so much! I seriously could use as much help as possible!

  2. #2
    Join Date
    Sep 2011
    Posts
    2
    I realized that I should of put the HTML as well, here is the HTML that I am working with.
    HTML Code:
    <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>

  3. #3
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,268
    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 04:33 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles