0

I need to select all images whose filename contain a certain string (variable) using jQuery. I am using:
var str='-out.';
$('img[src*='+str+']'). //do something

It works but fires the following warning in Firefox: " Expected ']' to terminate attribute selector but found '.' " Would someone know how to avoid this warning ?

Thank You

2
  • please provide the source code and the warning that's being fired. Commented Nov 5, 2010 at 18:23
  • Could you show as the warning ? Commented Nov 5, 2010 at 18:23

2 Answers 2

2

I think you need double quotes or single around the attribute value.

Look at Jquery Docs for attr*="value" selector

like this:

$("img[src*='"+str+"']")

OR

$('img[src*="'+str+'"]')
Sign up to request clarification or add additional context in comments.

1 Comment

Is in attribute selector specification (w3.org/TR/css3-selectors) that you will need the double quotes.
0

I try the following code and firefox doesn't fires any warning (it works as aspected)?

   var str=".png";
    $('img[src*='+str+']').each(function(){
      console.info(this.alt);
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.