This is my code. I am trying to load a website in a iframe. When the website is loaded, i would like to click in the iframe to select the div id (where i clicked) <iframe name="frameID" id="frameID" src="http://www.test.com" style="width:100%;height:400px;"></iframe> $(document).ready(function(){ $('#frameID').load(function(){ $('#frameID').contents().bind("click", function () { var a = $(this).id; alert (a); return false; }); }); Code (markup): For example, if i clicked in the footer of the website loaded in the iframe, i would like to display the div id "footer". However, i am unable to do so, it keep returning me undefined.
Install firebug extension and then add the following sentence: var a = $(this).id; console.log($(this)); This console.log() statement should log the contents of this and it should help you one step forward.