The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

What 's wrong with this code ?

View previous topic View next topic Go down

Solved What 's wrong with this code ?

Post by TamDonCo on September 6th 2016, 9:06 pm

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://hitsk.in/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 September 6th 2016, 10:10 pm; edited 1 time in total

TamDonCo
Forumember

Posts : 171
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 on September 6th 2016, 9:35 pm

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://hitsk.in/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://hitsk.in/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
Forumember

Male Posts : 33
Reputation : 12
Language : spanish

Back to top Go down

Solved Re: What 's wrong with this code ?

Post by TamDonCo on September 6th 2016, 10:05 pm

Thank You very much, Ch@lo Valdez

It works excellent

TamDonCo
Forumember

Posts : 171
Reputation : 2
Language : English

http://nhomcho.forummotion.com/

Back to top Go down

Solved Re: What 's wrong with this code ?

Post by SLGray on September 6th 2016, 10:09 pm

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


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


SLGray
Administrator
Administrator

Male Posts : 35667
Reputation : 2375
Language : English
Location : United States

http://fmthemes.forumotion.com/

Back to top Go down

Solved Re: What 's wrong with this code ?

Post by APE on September 7th 2016, 10:57 am

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





APE
Manager
Manager

Male Posts : 8333
Reputation : 718
Language : fluent in dork / mumbojumbo & English haha
Location : STUCK IN FORUMOTIONS SERVERS HELP ME !!!!!!

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

Back to top Go down

View previous topic View next topic Back to top


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