Using jQuery With Custom XHTML Attributes And Namespaces To Store Data

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:bn="http://www.bennadel.com">
<head>
	<title>Using jQuery With Custom XHTML Attributes</title>
 
	<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
	<script type="text/javascript">
 
		$(
			function(){
				var jLI = $( "li" );
 
				// Loop over each list istem to set up link.
				jLI.each(
					function( intI ){
						var jThis = $( this );
						var jLink = $( "<a></a>" );
 
						// Set the link text (trim text first).
						jLink.text(
							jThis.text().replace(
								new RegExp( "^\\s+|\\s+$", "g" ),
								""
								)
							);
 
						// Set the link href based on the IMDB
						// attribute of the list item.
						jLink.attr(
							{
								"href": jThis.attr( "bn:imdb" ),
								"bn:rel": "Pretty Cool Ladies"
							}
							);
 
						// Replace the LI content with the link.
						jThis
							.empty()
							.append( jLink )
						;
					}
					);
			}
			);
 
	</script>
</head>
<body>
 
	<h1>
		Pretty Cool Ladies
	</h1>
 
	<ul>
		<li bn:imdb="http://www.imdb.com/name/nm0004742/">
			Maria Bellow
		</li>
		<li bn:imdb="http://www.imdb.com/name/nm0184965/">
			Christina Cox
		</li>
		<li bn:imdb="http://www.imdb.com/name/nm0226459/">
			Ani DiFranco
		</li>
	</ul>
 
</body>
</html>

For Cut-and-Paste