1

I have a html with two iframes that change with a selector.

I would like to add an onclick event that triggers an url for some <rect> elements within the iframes.

I read the post jquery select iframe children and I think the solution has to be quite similar.

However I am quite inexperienced in jquery and haven't been able to find it myself.

My trials so far have been the following:

$("#frame").content().("rect").click(function() {
window.alert("sometext");
});

$("frame").content().("rect").click(function() {
window.alert("sometext");
});

$("#frame").content().$("rect").click(function() {
window.alert("sometext");
});
Community
  • 1
  • 1
Jon Nagra
  • 1,538
  • 1
  • 16
  • 36

1 Answers1

0

You miss find as also commented by @Rakesh.

Though it depends on your html code as well, does the iframe has id frame? Then use #frame if it has class frame use .frame. If rect is an element just use rect like in below, if rect is an id use #rect and if rect is a classname use .rect.

$("#frame").contents().find("rect").click(function() {
    window.alert("sometext");
});
Niki van Stein
  • 10,564
  • 3
  • 29
  • 62
  • Thanks for the prompt response. Indeed the issue was the find function. Also, after debugging a bit I found out I misspelled content() which should be contents(). – Jon Nagra Nov 13 '15 at 10:37