2014-10-17 95 views
-3

要紧类我体内从中我需要选择班级hs-content-path-history-of-data-pagetopic2013选择从字符串

<body class="blog-template hs-blog-id-1815512257 hs-blog-listing hs-content-path-history-of-data-pagetopic2013 hs-blog-name-history-of-data-page"></boby> 

var bodyClass = $('body').attr('class'); 
// select needfull class from var above 

if(selectedClass === 'hs-content-path-history-of-data-pagetopic2013'){ 
    // it works! 
} 

一些类如何可以选择从体类hs-content-path-history-of-data-pagetopic2013

+0

什么是我们的实际需要? – 2014-10-17 08:05:13

+0

bodyClass returns me - “blog-template hs-blog-id-1815512257 hs-blog-listing hs-content-path-history-of-data-pagetopic2013 hs-blog-name-history-of-data-page”。从这个字符串我需要选择这个类“hs-content-path-history-of-data-pagetopic2013”​​ - 然后,当我得到它我需要比较它whith“hs-content-path-history-of-data -pagetopic2013“并在此之后执行操作 – Mongo 2014-10-17 08:08:16

回答

2

要检查身体,或任何元素,具有一定的阶级,您可以使用hasClass

if ($('body').hasClass('hs-content-path-history-of-data-pagetopic2013')) { 
    ... 
} 
+0

WOOOW,tnx adeneo,你一如既往伟大! – Mongo 2014-10-17 08:10:10

+0

不客气! – adeneo 2014-10-17 08:13:11