The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

What 's wrong with this code ?

4 posters

Go down

Solved What 's wrong with this code ?

Post by TamDonCo Tue 06 Sep 2016, 20:06

I have 2 images ( image 1 and image 2 )

click on image 1 and image 2 on/off alternately


but it does not work ?


Code:
$(function(){

$("body").append('<div class="vietkeybutton">

<img src="http://2img.net/s/t/20/71/96/i_folder_new.gif" onclick="MyFunction();var img = document.getElementById("imgInfo");if (img.style.visibility === "hidden")  img.style.visibility = "visible"; else img.style.visibility = "hidden";"  />

<img id="imgInfo" src="https://upload.vstanced.com/images/2016/09/06/NQW.png" style="visibility:hidden" />

</div>')

});


Last edited by TamDonCo on Tue 06 Sep 2016, 21:10; edited 1 time in total
TamDonCo
TamDonCo
Forumember

Posts : 427
Reputation : 2
Language : English

http://nhomcho.forummotion.com/

Back to top Go down

Solved Re: What 's wrong with this code ?

Post by Ch@lo Valdez Tue 06 Sep 2016, 20:35

try:

Code:

function change_img(){
    var img=document.getElementById("imgInfo");
    img.style.visibility ==="hidden" ? img.style.visibility="visible"  : img.style.visibility="hidden";
};

$(function () {

    $("body").append('<div class="vietkeybutton"><img src="http://2img.net/s/t/20/71/96/i_folder_new.gif" onclick="change_img();"/><img id="imgInfo"src="https://upload.vstanced.com/images/2016/09/06/NQW.png" style="visibility:hidden"/></div>')

});

or better:

Code:

function change_img(){
    var img=document.getElementById("imgInfo");
    img.style.visibility ==="hidden" ? img.style.visibility="visible"  : img.style.visibility="hidden";
};
$(function () {
    var a = '<div class="vietkeybutton"><img src="http://2img.net/s/t/20/71/96/i_folder_new.gif" onclick="change_img();"/><img id="imgInfo"src="https://upload.vstanced.com/images/2016/09/06/NQW.png" style="visibility:hidden"/></div>';
document.body.insertAdjacentHTML('beforeend', a);
});
Ch@lo Valdez
Ch@lo Valdez
Forumember

Male Posts : 138
Reputation : 50
Language : spanish

Back to top Go down

Solved Re: What 's wrong with this code ?

Post by TamDonCo Tue 06 Sep 2016, 21:05

Thank You very much, Ch@lo Valdez

It works excellent
TamDonCo
TamDonCo
Forumember

Posts : 427
Reputation : 2
Language : English

http://nhomcho.forummotion.com/

Back to top Go down

Solved Re: What 's wrong with this code ?

Post by SLGray Tue 06 Sep 2016, 21:09

Is this solved? If yes, please mark the topic with the solved topic icon.


What 's wrong with this code ? Slgray10

When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.
SLGray
SLGray
Administrator
Administrator

Male Posts : 51522
Reputation : 3523
Language : English
Location : United States

https://forumsclub.com/gc/128-link-directory/

Back to top Go down

Solved Re: What 's wrong with this code ?

Post by Ape Wed 07 Sep 2016, 09:57

Problem solved & topic archived.
Please read our forum rules:  ESF General Rules


What 's wrong with this code ? Left1212What 's wrong with this code ? Center11What 's wrong with this code ? Right112
What 's wrong with this code ? Ape_b110
What 's wrong with this code ? Ape1010
Ape
Ape
Administrator
Administrator

Male Posts : 19366
Reputation : 2006
Language : fluent in dork / mumbojumbo & English haha

http://chatworld.forumotion.co.uk/

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum