How can I get only first grade? var GetFirstCla...">Geek Answers HandbookJQuery - if two classes - get the firstExample:Here we have <p class="tab1 current"></p>How can I get only first grade?var GetFirstClass = $('p').attr('class').filter(':first'); ??Any help is greatly appreciated.+4jqueryIladarsda Jul 05 '11 at 14:35source share4 answersUse JavaScript split : $('p').attr('class').split(' ')[0] Demo+13Town Jul 05 '11 at 14:39source share $('p').attr('class').split(' ')[0] +6Chris pratt Jul 05 '11 at 14:38source shareYou can split string based on a space.+2Daniel A. White Jul 05 '11 at 14:38source share $('<div class="ab"/>').attr('class').split(' ')[0] 0a'r Jul 05 '11 at 14:38source shareMore articles:the problem with the wpf command is not executed when the button is clicked - wpfGetting NSManagedObjectContext - iosExecute the rule for analyzing the startup code using the FxCop 10 - .net GUI fooobar.comWhy does AppleScript always send keystrokes with Command down? - applescriptHow to start a thread on a specific core? - multithreadingHide panel displays spaces (even if the frame is full-screen) - objective-cZk enabled .zul non-wotk page with main controller - includeSquiz Matrix vs Other CMS - joomlaChanging Magento Product Status in Different Store Types - productScala map containing mixing type values - scalaAll Articles
Example:
Here we have <p class="tab1 current"></p>
<p class="tab1 current"></p>
How can I get only first grade?
var GetFirstClass = $('p').attr('class').filter(':first'); ??
var GetFirstClass = $('p').attr('class').filter(':first');
Any help is greatly appreciated.
Use JavaScript split :
split
$('p').attr('class').split(' ')[0]
Demo
You can split string based on a space.
$('<div class="ab"/>').attr('class').split(' ')[0]