Tuesday, September 14, 2010

Using jQuery Selectors : Using tag name

Using jQuery Selectors
  tag name, ID, and class. They can be used either on their own or in combination with other selectors.             
Three building blocks of selectors are

Selecting HTML elements with tag name.


The following example demonstrates how to select all div elements and assign a text value into it within  an HTML page.
syntax:
 $(element name)  : which returns all matched html elements.
 $('element name').text('text to display'); : which assign the text value into all matched element.
Eg:
Add following in html head

<script type="text/javascript">
$(
}
function DisplayAll() {"div").text("Welcome to my first jQuery application.");</script>
Add following in html body

<input id="Button1" type="button" value="Display Text onclick="DisplayAll()" /><div></div><hr />
<div></div><hr /><div></div><hr /><div></div><hr />

No comments: