Add OnClick Function to newly created image that

I’m needing to dynamicly add a onclick that can focus on itself so when clicked it will add the width and remove it

function addimage2(where) { 
  var img = document.createElement("img");
  img.src = "swatch.jpg";  
  img.width = 300;
  where.parentNode.appendChild(img);
}

old method

<img src="swatch.jpg" alt="swatch-sm" onClick="addimage2(this);">

I need it like this as new images are created dynamicly

img.onclick = function(this){
   if(this.width == 300) {
      this.removeAttribute("width");
   }else{
      this.setAttribute("width","300");
   }
}

156 thoughts on “Add OnClick Function to newly created image that”

  1. What i do not understood is in fact how you’re now not really much more neatly-favored
    than you might be right now. You’re so intelligent.

    You realize therefore significantly when it comes to this matter, made
    me in my opinion consider it from numerous various angles.
    Its like men and women don’t seem to be interested except
    it’s one thing to do with Lady gaga! Your personal stuffs outstanding.
    Always deal with it up!

    Reply
  2. I am curious to find out what blog system you are utilizing?

    I’m experiencing some small security problems with my latest website
    and I would like to find something more safeguarded.
    Do you have any solutions?

    Reply
  3. Hi! I could have sworn I’ve been to this website before
    but after reading through some of the post I realized it’s new to me.
    Anyways, I’m definitely delighted I found it and I’ll be bookmarking and checking back
    often!

    Reply
  4. Does your website have a contact page? I’m having a tough time locating it but, I’d like to send you an e-mail.

    I’ve got some ideas for your blog you might be interested in hearing.
    Either way, great site and I look forward to seeing it grow over time.

    Reply
  5. pharmacie brink aix en provence pharmacie bultez amiens pharmacie homeopathie angers , pharmacie de garde eure pharmacie en ligne tadalafil , pharmacie des terrasses argenteuil pharmacie avignon cap sud traitement fer immunoplus acheter, immunoplus livraison rapide [url=https://roundme.com/@immunoplus412/about#]immunoplus [/url] Achat immunoplus bon marchГ© immunoplus acheter. pharmacie de garde kenitra pharmacie place des justices angers Vente petmend spray sur internet, Ou acheter du petmend spray [url=https://www.crackedracquets.com/forums/topic/prix-des-licences-petmend-spray/#]petmend spray [/url] petmend spray achat en ligne France Recherche petmend spray moins cher. therapies york pharmacie lafayette oxymetre , pharmacie uzan boulogne billancourt pharmacie mairie beauvais Acheter kiwof for cats en ligne, Acheter kiwof for cats en Belgique [url=https://www.crackedracquets.com/forums/topic/acheter-licence-kiwof-for-cats/#]Ou acheter kiwof for cats au meilleur prix[/url] Logiciel kiwof for cats Г  vendre Achat kiwof for cats pas cher. medicaments infection urinaire pharmacie de garde marseille saint louis .

    Reply
  6. Just wish to say your article is as amazing. The clearness in your post is simply spectacular and i could assume you’re an expert
    on this subject. Well with your permission allow me to grab your feed to keep up to
    date with forthcoming post. Thanks a million and please continue the rewarding work.

    Reply
  7. I like the helpful information you provide on your articles.
    I will bookmark your blog and test again here regularly.

    I’m somewhat certain I’ll learn plenty of new stuff proper here!
    Good luck for the next!

    Reply
  8. Hey There. I found your blog using msn. This is a really well written article.
    I’ll be sure to bookmark it and come back to read more of
    your useful info. Thanks for the post. I will certainly comeback.

    Reply
  9. I just could not go away your web site prior to suggesting that I actually enjoyed the usual info an individual provide to your visitors?
    Is gonna be again continuously to check up on new posts

    Reply
  10. We stumbled over here different web address and
    thought I may as well check things out. I like what I
    see so now i’m following you. Look forward to looking at
    your web page for a second time.

    Reply

Leave a Comment