9lessons programming blog
Loading Search
Wednesday, November 4, 2009

Jquery Basics Series - 2

Very good response about "Jquery Basic Series - 1". Last series discussed about jquery installation and introduction. In this post I want to explain about animation Effects and Attributes.



Effects

Fading Out and In : $(selector).fadeOut() and $(selector).fadeIn()
Sliding Up and Down : $(selector).slideUp() and $(selector).slideDown()
Sliding Toggle : $(selector).slideToggle()
Custom animation effect : $(selector).animate() // I will discuss this in upcoming post.

Fading Effect
Fading Out and In the div tag id='box'. Here you can change the effect speed fadeOut(speed,callback) Eg. fadeOut("fast" or "slow"), fadeOut(300). Take a look at Live Demo
<script type="text/javascript">
$(function()
{

$('.fadeOut_box').click(function()
{
$('#box').fadeOut("slow");
//Sliding effect just replace fadeOut() to slideUp()
});

$('.fadeIn_box').click(function()
{
$('#box').fadeIn("slow");
//Sliding effect just replace fadeIn() to slideDown()
});

});
</script>
<body>
<a href="#" class="fadeOut_box">fadeOut()</a>
<a href="#" class="fadeIn_box">fadeIn()</a>
<div id="box"></div>
</body>
CSS code
#box
{
background-color:#96BC43;
border:solid 3px #333333;
height:160px;
margin-top:30px;
}

Attributes

attr()
Using this method attr() makes it easy to retrieve a property value from the matched element. $(selector).attr(properties); Eg Attributes: id, class, title, src, href, etc... Take a look at Live Demo
<script type="text/javascript">
$(function()
{
$('.link').click(function()
{
var id=$(this).attr("id");
var class=$(this).attr("class");
var href=$(this).attr("href");
alert(id);
alert(class);
alert(href);
});
});
</script>
<a href="http://9lessons.blogspot.com" class="link" id="901">link</a>



html()
Get the html contents (innerHTML) of the matched element. $(selector).html(). Take a look at Live Demo
<script type="text/javascript">
$(function()
{
$('.link').click(function()
{
var href=$(this).attr("href");
$("h1").html(href);
});
});
</script>
<a href="http://9lessons.blogspot.com" >Click </a>
Link HREF value : <h1></h1>

addClass()
Adds the specified class to each of the set of matched elements. $(selector).addClass(). Take a look at Live Demo

<script type="text/javascript">
$(function()
{
$('.changeclass').click(function()
{
$(".big").addClass("small");
});
});
</script>
<a href="#" class="changeclass" >Click </a>
<div class="big">9lessons.blogspot.com</div>

CSS Code
.big
{
font-size:106px;
}
.small
{
font-size:12px;
}

Sponsored Links

Share this post

Comments
{ 9 comments }
Anonymous said...

NICE. thank you

Yamil Gonzales said...

Thanks to your series I'm finally using jQuery ;) so thank you very much

Joao Quintero said...

Thank you very much, it´s a good tutorial like first part ... I´awaiting 3th parte :D ...!! joi

Ravi Kumar Tamada said...

You are always Best .. ThankU

Deepak Nigam said...

Really very helpful.Thank you

PHPHelp said...

Very helpfull,

http://phpdesktop.blogspot.com/

Anonymous said...

http://demos.9lessons.info/basics/effects.html# when i test IE , it showing error

azeem said...

usfull

Travelling said...

very usefull

Post a Comment

Subscribe now!Recent Posts

Categories

Subscribe now!Popular Posts

People Says

@9lessons thank you for the great tutorials, we truly appreciate your contributions to the design community.

Smashing Magazine

Like Me

follow me
products

9lessons labs

9lessons clouds

Android application

Chrome Extension