mardi 1 novembre 2016

How can i create and add an image to my page on click?

Im adding a small function to my page where when you click a button it adds the corresponding image on the page after a certain class.

I have tried several approaches to this 'basic' problem. i have been working on this problem for two days now with no luck.

After clicking my buttons to get some interaction, I quickly recieve the 'Aw, Snap!' error from google. I know my computer can handle grabbing few images and displaying them on the page.

here is a part of my code thats most likely causing the trouble. Ive tried taking this part out of my code out and it helped. I didnt get the error message anymore, but it obviously stopped performing what i wanted it to.

  var elem;
    function placeImg(type) {

    //creates and sets attributes for an img
    elem = document.createElement("img");
    elem.setAttribute("src", type+".png");
    elem.setAttribute("height", "50");
    elem.setAttribute("width", "40");
    elem.setAttribute("alt", type +' logo image');

    //puts image after the class original, its an input area
    //there is only one class tag with the name original
    $('#original').after(elem);


 }


 when an ids with these names are clicked
 $("#arrow, #barber,  #gas, #lion, #none").click(function() {

    //checks if the current input area has a length of 12 or less
    if($('#'+findCurrentEditor()).val().length <=12){
        placeImg(this.id);  //places the image somewhere
    } 

 });

Id appreciate anyone willing to try and help.

Thanks!




Aucun commentaire:

Enregistrer un commentaire