facebook

Change Image of Image Button

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #325007 Reply

    Agraffiti
    Member

    Hi,
    Images can be changed using code such as:

    
    document.getElementById('m1-main-image1').src = 'images/img.png';
    

    However, this doesn’t work for image buttons, because the src of the image in image buttons is defined in the main.css file (no src attribute in the main.html file). Is it possible to change the src of an image button through javascript?

    Also: I have a lot of these image buttons that run a script on click, and in the script I need the id of the button being pressed. Each script runs the same function with a parameter of the button being pressed’s id. However, instead of typing ‘m1-main-buttonblah1’, ‘m1-main-buttonblah2’, etc. in each buttons on-click action, I was wondering if there was a way to just get the id a simple way so I can use the same script for all the buttons. I tried ‘this.id’ but that didn’t work. If there’s a way to do this, it would make things much easier.

    #325013

    support-michael
    Keymaster

    @Agraffiti

    >, I was wondering if there was a way to just get the id a simple way so I can use the same script for all the buttons. I tried ‘this.id’ but that didn’t work. If there’s a way to do this, it would make things much easier.

    It is possible to get the clicked button’s Id. See the following snippet.

    
    // use this snippet to get the Id of the clicked button
       $(event.srcElement).attr('id')
    or
       $(event.currentTarget).attr('id') 
    
    #325021

    Agraffiti
    Member

    Could you explain the ‘$’ symbol? Is it basically just ‘document.getElementById’? Do I have to create a function ‘$’? I can’t find an agreed-upon answer anywhere.

    #325023

    support-michael
    Keymaster

    @Agraffiti

    I forgot to qualify my snippet. It is based on jquery syntax. MobiOne apps and webapps include the jquery framework so I took advantage of it. The $ is a factory method for the jquery object. If you are interested there are a ton of tutorials to quickly get you familiar with the basic jquery syntax.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Change Image of Image Button

You must be logged in to post in the forum log in