开发者

Javascript grab part of class

I have a string

<li class="views-row views-row-4 views-row-even views-row-last" style="overflow-x: hidden; overflow-y: hidden; float: left; width: 221px; height: 227px; ">  
  <div class="views-field-field-image-fid">
                <span class="field-conten开发者_StackOverflow社区t"><img class="imagefield imagefield-field_image" width="221" height="215" alt="" src="http://test.com/sites/default/files/1_03_2.png?1316715258"></span>
  </div>

  <div class="views-field-field-pager-item-text-value">
                <span class="field-content">hydraSense®h</span>
  </div>

  <div class="views-field-field-slide-text-value">
                <div class="field-content">hgfhfghgfhgfhhhgf</div>
  </div>
</li>

And I want to get the views-row-4 from <li class=" how could I get this? My method of splitting by class didn't seem to work.


The first step is to get the li element itself. The easiest way is to attach and id to the guy then you can use the following to get the DOM element.

var element = document.getElementById('theNewId');
var classAttr = element.getAttribute('class');
var second = classList.split(" ")[1];

This assumes the "views-row-4" class is always the second one in the class list. If it's not then we'd need some other criteria by which to search for the value

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜