jquery file extensions
i need one thing to do:
<li class="pdf"开发者_开发技巧><a href="#">failanosaukums.pdf</a></li>
<li class="excel"><a href="#">failanosaukums.exel</a></li>
<li class="word"><a href="#">failanosaukums.doc</a></li>
If file exstensions are pdf, add li class pdf, and doc, exel, mp3.
I think something like this
var ext = ul li a each split (.)
$(this).parent().addClass(ext)
If you can't do this server side when generating the rest of the html, this should work
$("ul.files a").each(function() {
var $this = $(this);
var text = $this.text();
var ext = text.substring(text.lastIndexOf('.') + 1);
$this.parent().addClass(ext);
});
I'm not really sure if what you're wanting is a good idea, but this will do it for you.
var files = $("li a");
files.each(function(idx, el) { $(el).parent().addClass($(el).text().split(".").pop()) });
I agree with everybody else that server side is the way to go, but if you must do it client side:
$('.downloads li').addClass(function() {
return $('a', this).text().split('.').pop();
});
Example - http://jsfiddle.net/RNvnL/3/
精彩评论