Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I select an iframe by the src attribute using jQuery? [closed]

My code:

HTML:

<iframe src="http://lorempixel.com/400/400/" width="400" height="400"></iframe>

JS:

$("iframe[scr*='http://lorempixel.com/400/400/']").css("border", "3px solid blue");

Jsfiddle:

Link to JsFiddle

Can seem to select the iframe via its source attribute.

Thank you in Advance.

like image 946
regnix Avatar asked Dec 07 '22 09:12

regnix


2 Answers

Solution

You have a typo, The correct attribute you should be referencing is src whereas your query is searching for an attribute named scr which doesn't exist.

so instead of

$("iframe[scr*='http://lorempixel.com/400/400/']").css("border", "3px solid blue");

you should have

$("iframe[src*='http://lorempixel.com/400/400/']").css("border", "3px solid blue");

Example

> here's a jsfiddle which shows this typo corrected


Reference:

  • http://reference.sitepoint.com/html/img/src
like image 61
Michael Zaporozhets Avatar answered May 21 '23 23:05

Michael Zaporozhets


You misspelled "src" in the jQuery selector. It is currently scr, it should be src. Fixed code:

$("iframe[src*='http://lorempixel.com/400/400/']").css("border", "3px solid blue");

And fixed JSFiddle: http://jsfiddle.net/Je3SG/1/

like image 24
Gawdl3y Avatar answered May 22 '23 00:05

Gawdl3y