How can I get only the first p7 class from this HTML element?
p7
HTML
<div id="myDIV" class="p7 nextclass class_tt">some content</div>
Javascript
$('#myDIV').attr('class').first(); //will not work
$('#myDIV').attr('class').split(' ')[0];
$('#myDIV').attr('class') returns a string. split(' ') split into an array using ' ' as a separator.
$('#myDIV').attr('class')
split(' ')
' '
You can use split () to do this:
var firstClass = $('#myDIV').attr('class').split(' ')[0];
Source: https://habr.com/ru/post/1346931/More articles:Music stops when the screen rotates using MediaPlayer in Android - androidiTextSharp - Some pages are not marked as expected - itextsharpHttpWebRequest-independent HTTP library - httpFinding an unused connection in a SQL query - sqlIn what scenarios will a SecurityException be implemented in .NET? - .netuse python to generate graphs in excel - pythonapplication / plain MIME for text? - mime-typesExpand / collapse HTML tables - javascriptJQuery error: missing (before formal parameters - javascriptHow could I program spider movements? - javaAll Articles