boy18nj (112) [Avatar] Offline
#1
If I run this script-
$("a[href^='http://']").addClass("wrappedElement");

It shows 1 matched element, which is correct.

But if run-
$("img[src^='images']").addClass("wrappedElement");

It shows 0 matching elements, I expected 6 matched elements to be displayed.

Why I do see this discrepancy in results?
boy18nj (112) [Avatar] Offline
#2
Re: Chapter-2 Running Selectors Lab- not getting result as intended?
When I run this script, it solved the issue and it is returning 6 matched elements as expected-

$("div img[src$='jpg']").addClass("wrappedElement");

Now I am more confused, in case of href, it is a child of li which is further child of ul. We does not need to iterate thru the hierarchy in order to run this-

$("a[href^='http://']").addClass("wrappedElement");

Then why we need to iterate when finding img src value 'jpg'?
mraj (104) [Avatar] Offline
#3
Re: Chapter-2 Running Selectors Lab- not getting result as intended?
See if this answers your question:
http://www.manning-sandbox.com/thread.jspa?messageID=104187

i.e., I think it has to do with the src being converted to a full path to a file inside the DOM.
-- Mark