How to change the width for all elements given a specific class?
I need to change the width of all div elements with a specific class. For
example:
<div class="grid1 first">
<div class="grid2">
<div class="grid3">
<div class="grid4 last">
All the DIVs have initial width of 23%. DIVs with "first" or "last" class
need to have additional 1% width. I tried with this code:
var addwidth = 0;
$("[class^=grid]").each(function() {
if ($(this).hasClass("first") || $(this).hasClass("last")) {
addwidth += $(this).width() + 1 + "%";
$(this).width(addwidth);
}
});
Thank you.
No comments:
Post a Comment