jQuery - prop()

The prop() method sets or returns properties and values of the selected elements.

When this method is used to return the property value, it returns the value of the FIRST matched element.

When this method is used to set property values, it sets one or more property/value pairs for the set of matched elements.

Note: The prop() method should be used to retrieve property values, e.g. DOM properties (like tagName, nodeName, defaultChecked) or your own custom made properties.

To remove a property, use removeProp().

 

Hello World

 


    $("#btnGet").click(function ()
    {
        var propValue = $("#demo1").prop("class");
        $("#demo1").html("The current property of this header is " + propValue + ".");
    });

    $("#btnSet").click(function ()
    {
        $("#demo1").prop("class", "text-white")
        $("#demo1").html("Setting the css class to text-white....");
    });