官术网_书友最值得收藏!

Styling the borders of a group of elements

In this recipe, we'll see how to use one style declaration phrase to alter any group of selected elements.

Getting ready

When a group of elements must have borders, we can style them all with just one call. Just as we apply styles to a single element through the Element.setStyle() and Element.setStyles() methods, our groups of elements can be styled just as easily.

How to do it...

This example demonstrates the changing of a single property with setStyle() as well as the changing of multiple style properties with the setStyles() method.

<script type="text/javascript" src="mootools-1.3.0.js"></script>
</head>
<body>
<form action="javascript:" method="get">
<input id="go_bold" type="button"
value="Set Borders on a Group"/>
<input id="go_div" type="button" value="Set Authors Apart"/>
</form>
<br/>
<div>Every great man nowadays has his disciples,
and it is always Judas who writes the biography.
<span class="quote_author">Oscar Wilde</span></div>
<div>A hard man is good to find.
<span class="quote_author">Mae West</span></div>
<div>Any man who reads too much and uses his own brain
too little falls into lazy habits of thinking.
<span class="quote_author">Albert Einstein</span></div>
<div>Do not be anxious about tomorrow, for tomorrow will be
anxious for itself.
<span class="quote_author">Jesus of Nazareth</span></div>
<div>A successful man is one who can lay a firm foundation
with the bricks others have thrown at him.
<span class="quote_author">David Brinkley</span></div>
<script type="text/javascript">
$('go_bold').addEvent('click', function() {
// set the borders on the div elements
$$('div').setStyle('border','1px solid #ABABAB');
$$('.quote_author').setStyle('font-weight','bold');
});
$('go_div').addEvent('click', function() {
// use an object to set many style properties at once
$$('.quote_author').setStyles({
'display': 'block',
'text-decoration': 'underline',
'font-weight': 'bold',
'font-style': 'italic',
'font-size': '18px',
'margin': '5px 0 20px 5px'
});
});
</script>

How it works...

We use classes to grab groups of elements rather than attempting to grab each individual element by unique ID.

主站蜘蛛池模板: 旬邑县| 荃湾区| 随州市| 平远县| 湟源县| 沅江市| 哈尔滨市| 蓝山县| 芜湖市| 广西| 阳高县| 陆川县| 新化县| 聂荣县| 依安县| 特克斯县| 正阳县| 乌拉特后旗| 澄城县| 南皮县| 琼结县| 宁阳县| 会泽县| 漳州市| 赞皇县| 襄城县| 南投县| 南乐县| 安远县| 郯城县| 上杭县| 三门县| 十堰市| 虞城县| 浠水县| 宁明县| 泸州市| 元朗区| 六盘水市| 巨鹿县| 巴林右旗|