I'm trying to make it so when you click on an image loaded with jQuery it will trigger something, I decided to use the "onclick" event using html to run a jQuery script but there seems to be an error.
Error:
Unexpected token "/"
Code:
$("<img>").attr("src", item.preview.medium).attr("style", "margin-right:1%;margin-top:1%;").attr("onclick",
"$('#placeholder').html('<object type="application/x-shockwave-flash"
style="float:left;margin-left:1%;margin-bottom:1%;" height="378" width="620"
id="live_embed_player_flash"
data="http://www.twitch.tv/widgets/live_embed_player.swf?channel=' + item.channel.display_name + '&auto_play=false"
bgcolor="#000000">
<param name="allowFullScreen" value="true" />
<param name="allowScriptAccess" value="always" />
<param name="allowNetworking" value="all" />
<param name="movie" value="http://www.twitch.tv/widgets/live_embed_player.swf" />
<param name="flashvars" value="hostname=www.twitch.tv&channel=' + item.channel.display_name + '&auto_play=false&start_volume=25" />
</object>')").appendTo("#content");
New Code:
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$.getJSON("https://api.twitch.tv/kraken/search/streams?q=path%20of%20exile&callback=?", function (data) {
$.each(data.streams, function (index, item) {
$("<img>").attr("src", item.preview.medium).attr("style", "margin-right:1%;margin-top:1%;").attr("id", "imgg").appendTo("#content");
$("#imgg").click(function() {
var obj=$( "<object></object>",
{ "style" : "float:left;margin-left:1%;margin-bottom:1%;",
"height": "378", "width": "320", "bgcolor": "#000000",
"id" : "live_embed_player_flash",
"data" : "http://www.twitch.tv/widgets/live_embed_player.swf?channel=" + item.channel.display_name + "&auto_play=false"
});
$('#placeholder').empty().append(obj);
})
});
});
</script>
Error:
http://gyazo.com/5cd42fd599822344b0a00c5f8f5e63ab.png
It only gets this error when I click on the image btw.