I have a with the
rel=\"example.jpg\"
. I want the button to load the image in my #area
DIV, just after
HTML
<button data-rel="example.jpg">Click Me</button>
jQuery
$("button").click(function () {
var imgUrl = $(this).data('rel');
$("#area").html("<img src='" + imgUrl + "' alt='description' />");
});
Change your code to this:
$(document).ready(function(){
$("button").click(function(){
var imgUrl = $(this).data('rel');
$("#area").html("<img src='" + imgUrl + "' alt='description' />");
});
});
<button data-rel="example.jpg">Click Me</button>
<div id="area"></div>
Fiddle: http://jsfiddle.net/x3QdU/4/
change
<button rel=
to
<button data-rel=
http://jsfiddle.net/x3QdU/1/