I have seen something really cool at Yippy
They are loading the url in to an iframe for a quick view. I would like to do the same for my website. I'm using the bing API, example: JsFiddle
So I appended an iframe and a div to trigger the load event:
<div class="blok"></div>
<iframe class="ifram" src="" width="100" height="100"></iframe>
And I tried this for the event:
$(".block").click(function () {
$(".ifram").attr("src", (".desc a", this).text() );
});
Doesn't work.
It seems like a syntax error.
$(".block").click(function () {
$(".ifram").attr("src", $(".desc a", this).text() );
});
you forgot to put "$" before (".desc a", this).text()
.
There's about 6 things wrong:
.click()
, but the results are added dynamically, therefore you need to use a live handler such as .on()
.blok
in the html, but you're binding the event to .block
.ifram
element$
in front of your selectorThe following code should do what you want:
$("body").on('click', '.blok', function () {
$(this).siblings(".ifram").attr("src", $(this).siblings('p.desc').find('a').attr('href') );
});
jsFiddle: http://jsfiddle.net/aHCT5/18/