skip to Main Content

I need to hide a field on a page using JavaScript. I’ve hidden the field successfully by doing this

$('[name="EndorsementTypeID"]').hide();

However, I am unable to hide the label. This is how the label and the field is defined so not sure what I am doing wrong.

<li>
     <label for="EndorsementTypeID">Endorsement Type:&nbsp;</label>
     <b>
       <select id="EndorsementTypeID" name="EndorsementTypeID" aria-label="Endorsement Type"> 
           <option value="-1">[No Endorsement Type]</option>
           <option value="1">TEST</option>
       </select></b>
 </li>
    

2

Answers


  1. This:

    $('[name="EndorsementTypeID"]').hide();
    

    Selects this element:

    <select id="EndorsementTypeID" name="EndorsementTypeID" aria-label="Endorsement Type">
    

    Based on its name attribute. So to select this element:

    <label for="EndorsementTypeID">
    

    You could also use an attribute:

    $('[for="EndorsementTypeID"]').hide();
    
    Login or Signup to reply.
  2. Visit https://area51.stackexchange.com/ regularly! Use angle brackets to force linking: Have you seen https://superuser.com?

    To create fancier links, use Markdown:

    Here’s a link! And a reference-style link to [a panda][1]. References don’t have to be [numbers][question]. [1]: https://notfound.stackexchange.com/ [question]: https://english.stackexchange.com/questions/11481

    You can add tooltips to links:

    Click [here](https://diy.stackexchange.com "this text appears when you mouse over")! This works with [reference links][blog

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search