GithubHelp home page GithubHelp logo

jquery-practice's Introduction

#Recap on jQuery

The following are a series of concise exercises about jQuery

##Part One:

  • Selecting Nodes by ID
  • Selecting Nodes by ClassName
  • Selecting Nodes by AttributeValue
  • Selectiong Input Nodes
  • Additional Selector Features

####Selecting Nodes by ID

Is really easy to select a HTML element with jQuery by using the element's id.

$(document).ready(function(){
	$('#elementId').html());
});

You can also get different elements via the differnt IDs:

$(document).ready(function(){
	$('#firstElementId', '#secondElementId').html());
});

####Selecting Nodes by ClassName

This selector works as the one above.

$(document).ready(function(){
	$('.elementClass').html());
});

By selecting class elements, you can for instance change their CSS, as in the example below:

$(document).ready(function(){
	$('.firstElementClass', '.secondElementClass').css('background-color', ' green');
});

With this jQuery function, you will chenge the background color of .firstElementClass and .secondElementClass into green.

####Selection Nodes by AttributesValues

Your selection is based on attribute name and/or value. In this case you will be using brackets.

$(document).ready(function(){
	$('a[title]').html());
});

You are selecting all the <a> elements that have a title attribute. Or, you can be even more specific:

$(document).ready(function(){
	$('a[title="Hello World"]').html());
});

In this case you are selecting all the <a> elements that have a "Hello World" title as attribute value.

####Selecting by InputNodes

For selecting inputs elements like: input, button, image, etc. This is the basic syntax:

$(':input')

It selects everything associated with a form.

####Additional Selector Features

#####Contains selector

The :contains() selector searches for matching text.

$('div:contains("hello")')

In this case we want to select a div that contains the text "hello". The contains() search is case-sensitive.

#####Even or Odd Rows in a table selector

The $('tr:odd') and $('tr:even') is the jQuery syntax for selecting odd and even rows.

#####Selecting First Child This is the syntax for selecting the first-child: $('element:first-child').

$('span:first-child')

It will search in all the spans and select all the first-child in the spans.

#####Using starts whitin Selectors

If you need to select all the elements with an attribute that begins with a started value, this will be the basic syntax: [attribute^="value"]. Below is an example:

$('input[value^="Events"]')

And the HTML looks like this:

<input type="button" value="Events-One"/>

Above you are selcting any input whose value attribute begins with "Events". If you want to select all the input that ends with the word "Events" the code will look like this:

$('input[value$="Events"]')

While, if you just want to select all the input that contains "Events" in the value attribute, your syntax will look something like:

$('input[value*="Events"]')

jquery-practice's People

Contributors

giorgia-amici avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.