Question : jQuery Attribute selector problem

Hi there,

I am having trouble using the Attribute starts with selector against images.

Attached is my sampel code that I am trying .. but I cannot get it to select the images with the id's that start with 'err' ... and not the image where the id = 'not_me'

This code I have finds none.

I want to replace the image SRC on all images where the id starts with 'err'

Please help!

Thx Scoitt
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		<title>selector starts with...</title>
	</head>
	<body>
	</body>
</html>
<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.min.js"></script>
</head>
<body>

  <input id="t1" name="t1"><img src="lilerr.gif" id="err_1" /><br>
  <input id="t2" name="t2"><img src="lilerr.gif" id="err_2" /><br>
<img id="not_me" src="info_24.gif" /><br>
  
<script>
	
	if ($(":image[id^='err']").length > 0)
	{
	 alert('yes');
	 $(":image[id^='err']").attr("src","noerr.gif");
	}

</script>
</body>
</html>

Answer : jQuery Attribute selector problem


      if ($("img[id^='err']").length > 0)
      {
       alert('yes');
       $("img[id^='err']").attr("src","noerr.gif");
      }
Random Solutions  
 
programming4us programming4us