Results 1 to 3 of 3
  1.    #1  
    Hi!

    I declare my new button in html as
    Code:
    <span id="toggleDrawerButton" style="width: 60px; height:60px;"><img  src=" *my url from the internet*.png" /></span>
    But during running of my appl I want to change 'scr' from "*my url from the internet*.png" to other.

    How can I do?

    Or, probably,you know another way of making buttons with images with possibility of changing image.

    Thanks

    p.s.
    tried something like this: $('toggleDrawerButton').src="*new url*.png";
    but it doesn't work
    Last edited by Small-Poni; 01/15/2010 at 05:31 AM.
  2.    #2  
    Answering to myself

    Add id to img in html-file
    from
    Code:
    <span id="toggleDrawerButton" style="width: 60px; height:60px;"><img src="*my url from the internet*.png" /></span>
    to-->
    Code:
    <span id="toggleDrawerButton" style="width: 60px; height:60px;"><img  id="TEST" src="*my url from the internet*.png" /></span>
    then print in jsjsjs:
    Code:
       var floatimg = document.getElementById("TEST");
       floatimg.setAttribute("src", "new_url.png");
    And image will changed
  3. riskable's Avatar
    Posts
    9 Posts
    Global Posts
    10 Global Posts
    #3  
    To save some typing you could also just do this:

    Code:
    $("TEST").writeAttribute("src", "new_url.png");
    Explanation: The $() function is Prototype's wrapper for getElementById (it actually does more than just wrap it but that's not important for WebOS). writeAttribute() is Prototype's extension of the element object that performs setAttribute() with the addtional capability of being able to create said attribute if it doesn't already exist. For your example setAttribute() would work just as well (I'm just trying to demonstrate the "Prototype way").

    BTW: If you're going to make a lot of changes to your TEST element you should definitely assign it to a variable (like you did in your code above) since every call to $() or getElementById() has a cost. For example, I hate it when I see code like this:

    Code:
    $("TEST").hide();
    $("TEST").setAttribute("src", "image1.png");
    $("TEST").show();
    It is more efficient (less demanding on the browser) to do this:

    Code:
    var testElem = $("TEST");
    testElem.hide();
    testElem.setAttribute("src", "image1.png");
    testElem.show();
    -Riskable
    http://riskable.com
    "I have a license to kill -9"

Posting Permissions