slandau
slandau

Reputation: 24052

How to find number of specific images on page with JQuery

So I have an .aspx view that dynamically adds validation images to the page at runtime using some built in validation we added into the models. When you look at the code for the view, you can't see all of the image tags (which are instead generated on the fly). However, I would like a way to know whether or not any of these specific image tags are contained in the HTML that the user sees. Basically I want to know if the page has passed validation or not.

The image tag is this (found using the pointer tool of firebug, similar to Developer Tools in IE):

<img src="/Extranet/img/exclamation.gif" class="validation">

What would be a way of finding out if any of these images are on the current HTML page that the user sees (remember this can change when certain fields are updated), in JQuery, to know when the user has gotten rid of them all and therefore passed validation.

Thanks!

Upvotes: 0

Views: 601

Answers (2)

redsquare
redsquare

Reputation: 78667

if ( $('img.validation').length ) {
    //images exist
}

Upvotes: 0

Stefan Kendall
Stefan Kendall

Reputation: 67812

if( $('.validation').length > 0 )
{
   //images exist
}

This will check if there are any items with class validation on the page. To limit to just image checking, use img.validation.

Upvotes: 4

Related Questions