Ben 11

I asked a question related to this issue previously but, I decided that I was not specific enough before.

How exactly would I get Jquery to perform a specific function if it found 2 (or more) images with matching rel attributes?

1 answer

o.k.w 2355
This was chosen as the best answer

The following example performs a check on mouseover elements with "rel" attribute matching another same one and you can implement your script according to the matching count.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<script type="text/javascript" src=""></script>
<script type="text/javascript">
$(function() {
    if ($("img[rel='abc']").length > 1) {
        //do something if more than 1
        alert($("img[rel='abc']").length); //alert number of matching elements
    else if($("img[rel='abc']").length == 1) {
        //do something if matches 1
<img rel="abc" src="" alt="one" />
<img rel="abc" src="" alt="two" />
Answered over 9 years ago by o.k.w