javascript - How to get the class names using jquery? -
Hey, I'm wondering how can I use jquery to script dynamically under script.
The HTML output looks like this:
  & lt; Div id = "main-info-1" class = "maini" & gt; & Lt; P & gt; This is a paragraph. & Lt; / P & gt; & Lt; / Div & gt;   So, I'm trying to get the class name dynamically rather than hard coded like above.
There are two parts where I name the class in Jquery script:
  1.) Pc.children ('div.maini'). Remove (); 2.) Main_s = $ ('div.maini'). Remove (); As you can see, Class 'Menny' is hard coded and I am sure how to get the name of the class dynamically and put it properly in the script.   File:  
  & lt; Script type = "text / javascript" & gt; // Make them global to reach them from the console and handle them in // PaginationClick var maini_s; Var num_of_arts; Wise ipp; Click Function Handle Speed (new_page_index, pagyn_container) {var pc = $ (pagination_container); . Pc.children ('div.maini') removal (); (Var i = new_page_index * ipp; i & lt; (new_page_index + 1) * ipp; i ++) {if (i and lt; num_of_arts) {pc.append (maini_s [i]); }     }     return false; } $ (Document) .ready (function () {maini_s = $ ('div.maini'). Remove (); num_of_arts = maini_s.length; ipp = 3; // First parameter: Number of items // second parameter: Option Object $ ("#News-Pagination"). Pagination (6, {item_ on_page: ipp, callback: click on handle pointing});}); & Lt; / Script & gt;  
  Any help on this would be awesome, thanks. 
   
  It really depends on what you have after. 
  You can get the name of the square using jquery or plain javascript: 
   // jQuery $ myElement.attr ('class'); // javascript myElement.className  
  This will give you the string value of the element's  class  attribute. If the element contains more than one class (example:    
 
  
Comments
Post a Comment