RSS

code zone jQuery Crash Course – Day 1

05 Mar

Create a new HTML file.
include the jQuery library in source code with <script>

Example 1 : Display alert message

<script type="text/javascript" src="jquery.min.js"></script>
 <script type="text/javascript">
 $(document).ready(function(){

alert("Page loaded");
 });
</script>

In jQuery, accessing HTML elements is based on CSS selectors. You can use the HTML element, element id attribute or element class name to for reference purposes.

View this file using web browser. If everything works fine, you ‘ll see the alert message.

Example 2 : Hide content

$(document).ready(function()
{
$('div#content').hide();

});

Add the above code snippet within javaScript section and add a div container with some dummy text within body section. The div id is content for this scenario. When the browser loads the page you won’t see the text within the div container.

Example 3 : Hide and display content

<html>
<head>

<title>jQuery Examples</title>
<script type="text/javascript" src="jquery.min.js"></script>

<script type="text/javascript">
$(document).ready(function()
{
$('div#content').hide();
$('a#link').click(function()
{
$('div#content').show();
});

});
</script>
</head>

<body>
<a href="#" id="link">Click Me</a>

<div id="content">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.
</div>
</body>
</html>
Advertisements
 
Leave a comment

Posted by on March 5, 2012 in jQuery

 

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: