[jQuery] changing a class depending on content
<html>
<body>
Hi folks,
I've tried, but I just cannot get my head in the right direction with
this one.
In a non-ajax application I have, if a database record is successfully
updated, the return stream from the server contains an appropriate
message of the form:
<tt><p class="alert">The record was successfully
updated
</tt>If an error occurs, the message is of the form:
<tt><p class="alert">Error - the record was not
updated
</tt>I currently "jquery" the stream via:
<tt>
$(".alert").highlightFade({color:'red',speed:2000,iterator:'sinusoidal'});
</tt>I'd like now to be more user friendly and alter the fade colour to
red only if the message contains the word "Error", with the
colour to be green for all other messages.
The code below is my attempt, but it fails because I cannot work out how
to "transfer" the message to myString (for subsequent testing
of the presence of "Error" - how should I be doing
this?
<tt> $(".alert").filter(function(chekit){var
myString=???????;
//console.log(myString.indexOf("Error"))
if
(myString.indexOf("Error")>0)
{
$(".alert").highlightFade({color:'red',speed:2000,iterator:'sinusoidal'});
}
else
{
$(".alert").highlightFade({color:'green',speed:2000,iterator:'sinusoidal'});
};
});
</tt>What should be in ???? - I've tried $(this).html and similar
permutations, but none (of these guesses) worked.
Thanks,
Bruce
</body>
</html>