0
jQuery("#tdCatalogName").length 

I am using above given command in console.Even though element is there in the page ,it still gives zero as answer.Element is unique , I have verified that by searching the name of the element in the page source in IE9.

Only hint I am getting is that, "view page source" in the chrome doesn't show the element as part of page, but "view frame source" shows the element as part of page ,am I missing something? Please help.

Huangism
  • 16,278
  • 7
  • 48
  • 74
saket
  • 13
  • 8
  • Your current frame needs to be the same as the one containing the element. Related: http://stackoverflow.com/questions/3275816 Also related: http://stackoverflow.com/questions/5712187 – blgt Nov 12 '14 at 15:06
  • is the javascript code inside the main page or the frame? if its in the parent, jquery won't find elements in an iframe – Rhumborl Nov 12 '14 at 15:07
  • 1
    Try $("iframe").contents().find("#tdCatalogName").length; – Marian Gibala Nov 12 '14 at 15:09
  • @Rhumborl I am trying it from console ,how do i change the context in console so that commands from console can work their magic on the elements in the frame – saket Nov 12 '14 at 15:12
  • @saket see mgibala's comment – Huangism Nov 12 '14 at 15:12
  • @mgibala its working ,thanks for the quick help ,can someone suggest some good source where i can understand more about iframes, i am going to google about it anyways – saket Nov 12 '14 at 15:24

1 Answers1

0

Try this:

$("iframe").find("#tdCatalogName").length

or, as suggested by @mgibala:

$("iframe").contents().find("#tdCatalogName").length
Apul Gupta
  • 3,044
  • 3
  • 22
  • 30
  • The only thing `contents` does differently is return text nodes that are outside elements (as well as all elements). As the search is for an ID, using `contents()` should be pointless :) – iCollect.it Ltd Nov 12 '14 at 15:15
  • @TrueBlueAussie can you please explain in some more details,what are "text nodes outside elements" ?may be with some example. I ask this because the second part is working for me ,it returns 1 ,but the first part is not ,returns 0 – saket Nov 12 '14 at 15:23
  • @TrueBlueAussie, that's why I removed that in my answer but respected for other user's answer. :) – Apul Gupta Nov 12 '14 at 15:27
  • @Apul Gupta: I did say "should" be pointless. I am now *very* curious why `contents` would have any effect on this code. Does anyone have a JSFiddle to run some tests on? – iCollect.it Ltd Nov 12 '14 at 15:30