JSFiddle - React, Tailwind, and code Playground

by rodrigonery

HTML

<img src="http://pagead2.googlesyndication.com/simgad/13142881702525886175"/>

JavaScript

/*
 * This is my JS event listener on click unobstrusive...
 */
var $tagImg = $('img');
$tagImg.on("click", function () { 
    window.open("http://www.lisa22.me.pn/",
	"Lisa Window","location=1,status=1,scrollbars=1,width=200,height=200");
});

/*
 * This my other form..
 */
var $tagImg = $('#img');

// Now my $tagImg is getting my <img id="img" src="bablablabla"/>

/*
 * I can get a Class too, like: <img class="img" src="bablablalba"/>
 */
var $tagImg = $('.img');

// ... You can manipulate all the small things in jQuery and is like JS but is better and more easy.. 

// The Besttttttttttt way with Clean Code and a 
var setImgClick = (function () {
    var $tagImg = $('img');
    $tagImg.on("click", function () {
        window.open("http://www.lisa22.me.pn/", "Lisa Window","location=1,status=1,scrollbars=1,width=200,height=200");        
    });
});

// Now you can do:
setImgClick();

// Or you can set this with a normal function
function setImgClick() {
    var $tagImg = $('img');
    $tagImg.on("click", function () {
        window.open("http://www.lisa22.me.pn/", "Lisa Window","location=1,status=1,scrollbars=1,width=200,height=200");        
    });    
}

setImgClick();

// Anonymous function too

(function () {
    var $tagImg = $('img');
    $tagImg.on("click", function () {
        window.open("http://www.lisa22.me.pn/", "Lisa Window","location=1,status=1,scrollbars=1,width=200,height=200");        
    });        
}())

/*
 * This functions are good for your scope Global
 * but you know i can manipulate all atrributes with .attr(); or .prop(); in jQuery
 * and i can do this in javaScript too..
 * You can do it simple in JS if you want...
 */

function openWindow () {
    window.open("http://www.lisa22.me.pn/", "Lisa Window","location=1,status=1,scrollbars=1,width=200,height=200");
}

function setImgClick () {
    var $tagImg = document.getElementById("img");
    $tagImg.addEventListener("click", openWindow, false);
}

setImgClick();

/*
 * Now you can do...