Search code examples
jquerytargeting

Target specific value of a node with jQuery


OK, I basically have the following scenario with some dynamically generated html:

<div id = "main-hold">
    <ul class="main-class">
        <li class="item">
        <a tabindex="-50" title="Title 1" class="class aa" id="12365" href="#" target="">Learning outcomes<div class="end-icon"></div></a>

...

Basically I want to be able to show/hide objects of class "item" using the unique id referenced within, but am struggling to target it. Any thoughts appreciated

$("#main-hold").hide();

Successfully hides everything, but I haven't been able to drill down to the id level.


Solution

  • Here, try this one, hope this help :

    $(document).ready(function() {
       $('.item #12365').hide();
    
       $('#main-hold').on('click','.item', function(){
          $('.item #12365').toggle();
       });
    });