tags:

views:

5063

answers:

5

I would like to use a jquery to select the following span:

<span id="RequiredFieldValidator1" class="validationerror" style="color: Red; display: none;">*</span>

But not select the following span which differs from the original in that the style attribute has a display property whose value is inline instead of none.

<span id="RequiredFieldValidator2" class="validationerror" style="color: Red; display: inline;">*</span>

I am aware inline styles are evil but an asp.net web forms validator control is generating it and doing a lot of good as well as evil.

Can this be done using jquery selectors? I'm new to jquery.

+2  A: 

Try something like this:

$('.validationerror:hidden')
bendewey
+2  A: 
$("span[style*=inline]")

will select all span elements with the style attribute which has the value "inline" in it somewhere.

aleemb
Thanks for your quick response you actually answered my question as asked but the other solution was more elegant.
Craig McKeachie
This doesn't work<html><head></head><body><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script type="text/javascript"> $(document).ready(function(){ alert($("span[style*=inline]").length); } )</script><span id="RequiredFieldValidator2" class="validationerror" style="color: Red; display: inline;">*</span> </body></html>
Mike Blandford
A: 

embed the styles inside the classes and you have 2 class the use JQuery selector

$(".<ClassName>")
Rony
A: 

here is an advise for selecting server side controls too

document.getElementById("<%=txtFirstName.ClientID %>");

or

$("#'<%=txtFirstName.ClientID %>'");

or

$("[id$='_txtFirstName']");
A: 

I do something like this to add\remove an error style to the parent of the validation error control to highlight the control that caused the error and the validation message.

$('input').change(function() {
  $(".validationError[style*=hidden]").parent().removeClass("error");
  $(".validationError[style*=visible]").parent().addClass("error");
});
Justin Moore