JQuery Attributes
A jQuery Attributes used to get the DOM attributes of elements and set those attribute values.
Most of the common attributes are
Types of Jquery attributes :
- attr("<properties>")
- used to get the value of an attribute from the first one in the matched set of attributes.
- Example:- var val = $("a").attr("title");
- attr("<name>","<value>")
- Used to get and set the value of an attribute from first one in the matched set of attributes
- Example:- $("#myimage").attr("src", "mypic.jpg");
- removeAttr("<name>")
- Used to rome tha attribute with value from the mathced element.
- Example:- $("table").removeAttr("border");
- hasClass("<className>")
- It checks weather that particular element has that class or not and returns boolean value.ie., True/False
- Example:-var val = $("div#id1").hasClass("theme");
- addClass("<className>")
- It is used to add the class name to matched element or control.
- Example:-$("div#id1").addClass("theme");
- removeClass("<className>")
- It is used to remove the class from the matched element or control.
- Example:-$("div#id1").removeClass("theme");
- toggleClass("<className>")
- It is used to add the class name if the matched element has not particular class name. if it already contains it removes that particular class name.
- Example:-$("div#id1").toggleClass("theme");
- html() / html ("<Content>")
- These are used to get or set the content to the matched element.
- Example:-var content = $("div#id1").html();
- $("div#id1").html("content")
- text() / text ("<val>")
- These are used to get or set the combined text the matched element.
- Example:-var content = $("div#id1").text();
- $("div#id2").text("content")
- val() / text ("<val>")
- These are used to get or set the input value of the first matched element.
- Example:-var content = $("div#id1").val();
- $("div#id2").val("content")
Example:
In few days.
Post a Comment