Reputation: 29
I have the following code where if a Div called 'VALID_VAR_264' contains the word 'Required' then the class 'sponz' is added to the div.
However, how can I adapt this so that if the Div called 'VALID_VAR_264' contains 'Required' then I can get it to add the class 'sponz' to a different div.
Is this possible?
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">//<![CDATA[
$(window).load(function(){
jQuery('#VALID_VAR_264:contains("Required")').addClass('sponz')
});//]]>
</script>
Upvotes: 0
Views: 140
Reputation: 6923
You can get the length of the jQuery object and if it is greater than 0 execute the code you need to:
if(jQuery('#VALID_VAR_264:contains("Required")').length>0)
{
$(otherSelector).addClass('sponz');
}
Upvotes: 1