Just trying to get it to restyle each element depending on the content within the title so far, it only changes it based on the first one and ignores the other ones. When I use "each()" it should be checking each one and then changing the color to red for no blue for yes.
<html>
<head>
<title>colorme</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2 /jquery.js"></script>
<script>
$(document).ready(function(){
$(".test").each(function(){
var title = $(this).find('.taskName').attr("title");
if(title =="yes") {
$('div.taskName').css('color','blue');
}
else if(title =="no") {
$('div.taskName').css('color','red');
}
});
});
</script>
</head>
<body>
<div class="test">
<div class="taskName" title="yes">this should be blue</div>
<div class="taskName" title="no">this should not be blue</div>
<div class="taskName" title="yes">this should be blue</div>
<div class="taskName" title="no">this should not be blue</div>
</div>
</body>
</html>
Try like this:
var $div = $('div.taskName');
$div.filter('[title=yes]').css('color', 'blue');
$div.filter('[title=no]').css('color', 'red');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With