phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


jQuery: My First Code

Tag: jQuery, introduction   Category: JavaScript
post: 20 Mar 2008 read: 564


JQuery Introduction Step By Step Tutorial - Part 3: After create simple page, we try to apply jQuery at the page. In this post, we will practice how to modify css action with jQuery.

We want to modify page in order to be like this:

For this job, create a file named "myjs.js". Enter following code:


// JavaScript Document
$(document).ready(
  function(){
	$('.lyric-text').addClass('lyric-full');
  }				  
);

What mean? The fundamental operation in jQuery is selecting a part of the document. This is done with the $() construct. In this case, jQuery find lyric-text class. Then, jQuery inject new class named "lyric-full". This job use .addClass() method. So, we must add new class in our css, like this:


.lyric-full {
  font-style: italic;
  background-color:#FFFFCC;
  border: 1px solid #FF0000;
  padding: 0.5em;
}

Thus, open your mycss.css. Update like this:


@charset "utf-8";
/* CSS Document */

body {
  font: 75% Arial, Helvetica, sans-serif;
}

h1 {
  font-size: 2.5em;
  margin-bottom: 0;
}

h2 {
  font-size: 1.2em;
  margin-bottom: .5em;
}

h3 {
  font-size: 1.0em;
  margin-bottom:0;
}
.lyric{
  margin: 0 2em;
}
.lyric-full {
  font-style: italic;
  background-color:#FFFFCC;
  border: 1px solid #FF0000;
  padding: 0.5em;
}

Point your browser to http://localhost/test/jquery/myfirstjquery.html.



Series this article:
jQuery: Introduction
jQuery: Installation
jQuery: My First Code
jQuery: Using Event Handler

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting