Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

On a button click I am hiding all the field validator error by :

$(".field-validation-error").hide()

However I would need this to be activated for some of the fields but not for all.

Let's say I would need this to be activated for the following control.

<td>
      @Html.TextBoxFor(m => m.BookTitle, new { @id = "PTitle" })
</td>
<td style="color: Red; display: block; margin-right:20px;">

            @Html.ValidationMessageFor(m => m.BookTitle, "", new { @id = "pTitleModelError" })
</td>

I tried enabling it like this using Jquery,

$("#pTitleModelError .field-validation-error").show();

Without any luck. Am I missing something?

share|improve this question
1  
With the spacing your selector is currently looking for a child of #pTitleModelError remove the spacing in between – Patsy Issa 15 hours ago
@PatsyIssa somehow it is not working.. In a button click I was trying to hide all other erroe messages except this. As of now it is like this. $(".field-validation-error").hide(); $("#pTitleModelError.field-validation-error").show(); Its not validating that field. – TBA 14 hours ago
Are the elements nested in the same td ? – Patsy Issa 14 hours ago

2 Answers

If i understood your markup correctly the following should give you the desired result:

$("#pTitleModelError").siblings('.field-validation-error').show();

If i am mistaken let me know so i may help you further.

share|improve this answer

As I understand you want to hide all elements with .field-validation-error and show one with pTitleModelError Try...

$("#pTitleModelError").show();
share|improve this answer
he wants to show the #pTitleModelError that has the class field-validation-error – Patsy Issa 15 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.