Search code examples
javascriptjqueryjquery-selectors

jQuery next() - selector


I have a few sets of javascript codes and divs just below them:

     <script type='text/javascript'>
                    jQuery(document).ready(function(){
                        jQuery(".display").something({
                        /*myfunction*/
                        });
                    });
                </script>

        <div class="display"></div>  

     <script type='text/javascript'>
                    jQuery(document).ready(function(){
                        jQuery(".display").something({
                        /*myfunction*/
                        });
                    });
                </script>

        <div class="display"></div>      

(...)

Is there a way of selecting only the .display div after exact JS? I've been thinking about next() but it's hard to attach to document.ready ;)


Solution

  • Everything was generated dynamically (that's why I asked how to change my JS code, WITHOUT touching DOM!).

    Anyways I've found the best way.

    <?php $id = rand(); ?>
    
     <script type='text/javascript'>
                        jQuery(document).ready(function(){
                            jQuery(".display-"<?php echo $id;?>").something({
                            /*myfunction*/
                            });
                        });
                    </script>
    
            <div class="display-<?php echo $id;?>"></div>  
    

    Not perfect, but it works at least (and could possibly break, but chances are really low).