How to select an iframe using src attribute using jQuery?

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

It might seem like selecting the iframe via its original attribute.

Thank you in Advance.

+3


source to share


2 answers


Decision

You have a typo. The correct attribute you should refer to is src

, whereas your query is looking for an attribute with a name scr

that does not exist.

so instead of

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

      

you must have

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

      




Example

> here's a jsfiddle that shows this typo has been fixed


Reference:

+11


source


You misspelled "src" in your jQuery selector. For now scr

, it should be src

. Fixed code:

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

      



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

+3


source







All Articles