How to get class names dynamically? - jQuery

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • spyderfusion02
    New Member
    • Jan 2010
    • 2

    How to get class names dynamically? - jQuery

    Hi there, I am trying to get the class names dynamically for the script below.

    I am using the Pagination plugin. I have different class names that are created through PHP so need to get them using jQuery dynamically.

    As you can see below, there are two '#hiddenresult div.result'. 'result' is the static class name that needs to change since the class name will be populated with PHP.

    so, i want jquery to get the class name instead of me just hard coding it in as seen below.

    The jQuery file:
    Code:
    <script type="text/javascript">
    
            function pageselectCallback(page_index, jq){
            var new_content = $('#hiddenresult div.result:eq('+page_index+')').clone();
            $('#Searchresult').empty().append(new_content);
            return false;
        }
    
        /** 
         * Callback function for the AJAX content loader.
         */
        function initPagination() {
            var num_entries = $('#hiddenresult div.result').length;
            // Create pagination element
            $("#Pagination").pagination(num_entries, {
                num_edge_entries: 2,
                num_display_entries: 8,
                callback: pageselectCallback,
                items_per_page:1
            });
         }
    
        // Load HTML snippet with AJAX and insert it into the Hiddenresult element
        // When the HTML has loaded, call initPagination to paginate the elements        
        $(document).ready(function(){      
            initPagination();
        });
    </script>
    Any help on implementing a solution would be great. Thanks
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    i assume that you have the JavaScript code written in the page? then you could just use php to write the correct values there ... otherwise, when the script is included with a script tag you might populate a JavaScript-variable to the page that you might use in the script later on ...

    kind regards

    Comment

    Working...