开发者

Listing all unique class name that begin with a prefix

开发者 https://www.devze.com 2023-03-08 10:14 出处:网络
Well, lets see a markup as an example. <div class=\"_round_5\">Some text开发者_StackOverflow社区</div>

Well, lets see a markup as an example.

<div class="_round_5">Some text开发者_StackOverflow社区</div>
<div class="_brTop_5">Another Text</div>

My idea is to collect all the unique class name in a page that begin with a _ and post them to a different page, which will return me with a file that contains a generated CSS style based on those class name.

Now, How to collect all the unique class names that begin with a "_" or some other prefix also? The list might be an array or json. But I prefer json.


Try: http://jsfiddle.net/54kzu/3/

It correctly handles multiple classes, as you requested in the comments.

var uniqueClasses = [];

$('[class]').each(function() {
    var thisClasses = $(this).attr('class').split(/\s+/);
    $.each(thisClasses, function(i, thisClass) {
        if (thisClass.substring(0,1) == '_' && $.inArray(thisClass, uniqueClasses) == -1) {
            uniqueClasses.push(thisClass);
        }
    });
});

console.log(uniqueClasses);


you can use Start Selector

0

精彩评论

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