phpeveryday.com

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


jQuery - Selector: Modifying Style at List Item Levels

Tag: jQuery, $(), factory, function, selectors, css, list item, style   Category: JavaScript
post: 21 Mar 2008 read: 546


jQuery Selector Step By Step Tutorial - Part 2: In this post, we want to modify the top level items, and only the top level item. We arrange become horizontal. For this job, create a category class in the stylesheet.

Create a file named "song.css". Enter following code:


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

.category{
  float:left;
  list-style:none;
  margin: 10px;
}

Then, we write jQuery code. Create a file named "song.js". Enter following code:


// JavaScript Document
$(document).ready(function(){
  $('#favorite > li').addClass('category');
});

Before try, attach "jquery.js", "song.css", and "song.js" at your HTML header.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Beatles Song</title>
<link rel="stylesheet" href="song.css" type="text/css" media="screen">
<script src="jquery.js" type="text/javascript"></script>
<script src="song.js" type="application/javascript"></script>
</head>
<h1>My Favorite Beatles Song</h1>
<div id="description">These is all of my favorite song from The Beatles. How about you?</div>

<ul id="favorite">
  <li>Love
    <ul>
      <li><a href="love.html">Love me do</a>
      <li>Something
      <li>Here, There, and Anywhere
    </ul>
  <li>Balads
    <ul>
      <li><a href="obladi.pdf">Obladi Oblada</a>
      <li>Get Back
      <li>Help
    </ul>
  <li>Rock 'n Roll
    <ul>
      <li><a href="mailto:music.rock">Rock 'n Roll The Music</a>
        <ul>
          <li>Part 1
          <li>Part 2
        </ul>
      <li>Hard Days Night
      <li>Standing There
    </ul>
</ul>

<body>
</body>
</html>

Point your browser to this practice address.



Series this article:
jQuery - Selectors: Understanding The $() Factory Function
jQuery - Selector: Modifying Style at List Item Levels
jQuery - Selector: Styling Sub Level Item
jQuery - Selector: XPath Selectors
jQuery - Selector: Custom Selectors
jQuery - Selector: Choose a Style at Custom Selectors
jQuery - Selector: Modify Style for Table Header
jQuery - Selector: Styling Sibling
jQuery - Selector: Styling Next Cell

| 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