I have a view that displays a textbox as follows:
$(function() {
$('[name="CodeGuest"]').hide();
});
@Html.Label("CodeGuest")
i am used above code but does not hide the label.what can i do?
When you use @Html.Label("CodeGuest"), It will render the below HTML
<label for="CodeGuest">CodeGuest</label>
So your jQuery selector should look for items with that specific for property value like this
$(function() {
$('label[for="CodeGuest"]').hide();
});
I suggest you to use another overload of Html.Label helper method where you can specify the HTML attributes, thus define an ID element for the label.
@Html.Label("CodeGuest", new { @id="codeGuest"})
This will give you the markup with ID element so that you can use that to hide your element.
<label id="codeGuest" for="CodeGuest">CodeGuest</label>
Now your javascript code can be
$(function() {
$("#codeGuest").hide();
});
Always try to use SPECIFIC jQuery selectors ( ID's instead of classnames etc..) instead of generic. That is faster.