Thursday, February 3, 2011

Setting CSS Opacity with jQuery that Passes W3C Validation

Setting CSS opacity directly using jQuery is much more practical and easier to implement, because the code is exactly the same for all browsers and passes W3C validation as well. Let us see how jQuery sets CSS opacity on a div element.

<script type="text/javascript">
$(document).ready(
function()
{
$(".boxcaption").css({ opacity: .5 })
}
);
</script>

Here ".boxcaption" is a class name of a div element where the opacity .5 ( 50%) will take place.

That’s it.

No comments:

Post a Comment

Related Posts with Thumbnails