Page 1 of 1

get image element by id

Posted: Mon Jan 19, 2015 3:58 pm
by Vinny B

Hello

I have this code which is part of a bigger code.

var el=document.getElementById('myimage');

It works if I put Image inside a HTML window

but i am trying to use the Appery native image holder.

I tried
var el=Appery.getElementById('myimage');
var el=Apperyio.getElementById('myimage');

but doesnt work.

Any suggestions.

Thank You


get image element by id

Posted: Mon Jan 19, 2015 4:36 pm
by M&M

If you had an Appery Image component, you wouldn't be using the javascript "getElementById". That's the JS way of doing things :-)

For example say you had an Image component (with a name of 'myimg') and you wanted to get it's image path then you'd do something like this (in Appery io)

Apperyio.getImagePath('myimg');

And to receive the reference to the component with a particular name use the following API call:

Appery("component name")

Cheers,
M&M


get image element by id

Posted: Tue Jan 20, 2015 3:53 am
by Yurii Orishchuk

Hi Vinny,

that's correct - please follow described above..

Regards.


get image element by id

Posted: Tue Jan 20, 2015 4:03 am
by Vinny B

Thank You
Got it working


get image element by id

Posted: Wed May 18, 2016 4:57 am
by saurabh8122815

i'm trying to compare image path as this example. http://www.w3schools.com/js/tryit.asp?filename=tryjs_intro_lightbulb .

when i use alert(Apperyio.getImagePath('pimage')); i got only " ../img/pimage "

how can i get full image path so that i can compare both image SRC ?

my code :

var a= Appery('pimage').attr('src',Appery.getImagePath("a.png"));
if (a){
alert("id con");


Code: Select all

Appery('pimage').attr('src',Appery.getImagePath("b.png"));

}
else{
alert("else ");
Appery('pimage').attr('src',Apperyio.getImagePath("a.png"));
}

using this code, only if condition true EVERY time .

1st time, if i click on image - "if condition" true and image change. now again i click on that image again if condition are true.

if i click on image, "IF condition " true and image change and if i click again on image, image are change. (eg, image a.png > image b.png > image a.png )


get image element by id

Posted: Wed May 18, 2016 3:43 pm
by Serhii Kulibaba

Hello Saurabh,

That condition is always true, because of code pre Appery('pimage').attr('src',Appery.getImagePath("a.png"));/pre returns image element, which is present on the screen


get image element by id

Posted: Fri May 20, 2016 12:41 pm
by saurabh8122815

how to compare to image FULL path in appery.io ? like this example .

http://www.w3schools.com/js/tryit.asp...


get image element by id

Posted: Fri May 20, 2016 3:31 pm
by Serhii Kulibaba

You are able to read image's src with JS below:

prevar src = Apperyio('pimage').attr('src');/pre
and check it as it is shown in the link above:
preif (src.match("a")){
alert("a");
} else {
alert("b");
}/pre