jQuery HTML Predefined Functions

jQuery HTML


The jQuery library provides predefined functions to perform modifications of the content of  HTML elements.
...................................................................................................................................................................
Function
html()

Description
Changes the content of HTML elements, such as text in the <P> and <DIV> tag.

Syntax
$(selector).html(content)

...................................................................................................................................................................
Function 
append()

Description
Enables a user to append content after the inside content in the selected element.

Syntax
$(selector).append(content)

...................................................................................................................................................................
Function
prepend()

Description
Enables a user to append content before the inner content of selected elements.

Syntax
$(selector).prepend(content)

...................................................................................................................................................................
Function
remove()

Description
Removes the selected element including all the  text and nested elements inside it.

Syntax 
$(selector).remove()

...................................................................................................................................................................
Fumction
empty()

Description
Removes all the text and nested elements of selected elements . However, this  method doesnot remove the element.

Syntax
$(selector).empty()

..................................................................................................................................................................
Function
after()

Description
Inserts the content after the selected elements.

Syntax
$(selector).after(content)

..................................................................................................................................................................
Function
before()

Description
Inserts the content before the selected elements.

Syntax
$(selector).before(content)

...................................................................................................................................................................
Function 
text()

Description
Sets or returns the content of  selected elements.

Syntax
$(selector).text(content0

...................................................................................................................................................................
Function
val()

Description
Sets  or returns the values of the attributes of selected elements.

Syntax
$(selector).val(value)

...................................................................................................................................................................
Function
attr()

Description
Sets or returns the values and attributes of selected elements.

Syntax
$(selector).attr(attribute, value)


Accessing Function

Once you have created a function , you can call the same from any portion of the code where you want to use functionality provided by the function. A function can return a  value of nay data type to the calling code . Let us see how the function is called , how a value from a function  is returned , and how the value returned by a function is retrieved.

Calling a Function

A function is called by using the function name. The following syntax is used for accessing a function:

functionName ();
In the preceding syntax, functionName is the name of the function.

While calling a function , you can also pass an variable or value to it. The value or variable passed to the function is known as parameter. If parameter need to be provided , these are specified in parenthesis while calling the function. The following syntax is used for specifying  parameters in a function :

functionName (parameter1, parameter2, ....);

The following code illustrates how a function is ascessed:

<!DOCTYPE HTML>
<HTML>
<HEAD>
<SCRIPT type="text/javascript">
...
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT type="text/javascript"> product_category="Medicine";
tax("product_category ,"paracetamol",8000); product_category="Mobile";
tax("product_category ,"GV3",3000); tax("product_category ,"XV5",5000);
</SCRIPT>
</BODY>
<HTML>

Returning values to a Function

A function can return a value through a return statement. The following code illustrates how to return a value:

function functionName()
{
var variable=10;
return variable;
}
Consider the following code :

<!DOCTYPE HTML>
<HTML>
<HEAD>
<SCRIPT type="text/javascript">
function sum(a,b)
{
return a+b;
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT type="text/javascript"> total =sum (3 , 6);
document.write(total);
</SCRIPT>
</BODY>
</HTML>

In the preceding code, the sum () function accepts two numbers 3 and 6 as parameters and return their sum 9.


About Codingwelove

Codingwelove
Recommended Posts × +

0 comments:

Post a Comment