Vinny B
Posts: 0
Joined: Fri Aug 22, 2014 2:22 pm

get image element by id

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

M&M
Posts: 0
Joined: Tue Nov 11, 2014 6:59 am

get image element by id

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

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

get image element by id

Hi Vinny,

that's correct - please follow described above..

Regards.

Vinny B
Posts: 0
Joined: Fri Aug 22, 2014 2:22 pm

get image element by id

Thank You
Got it working

saurabh8122815
Posts: 0
Joined: Mon Mar 21, 2016 5:08 am

get image element by id

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 )

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

get image element by id

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

saurabh8122815
Posts: 0
Joined: Mon Mar 21, 2016 5:08 am

get image element by id

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

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

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

get image element by id

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

Return to “Issues”