0

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.