Using jQuery, how can I select all elements that have a class name beginning with "hello"?
<!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">
<head>
<title>Demo</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.hello*').each(function(index) {
alert($(this).attr('class'));
});
});
</script>
</head>
<body>
<h1 class="helloH">Heading</h1>
<div class="hello1">1</div>
<div class="hello2">2</div>
<div class="hello3">3</div>
<p class="nomatch">This should not be included</p>
<p class="helloP">ABC</p>
<p class="helloXYZ">XYZ</p>
</body>
</html>
Open in new window