.attr()
According to jQuery, it can get the value of an attribute for the first element in the set of matched elements or set one or more attributes for every matched element.So I use the img tag to add an apple image at the bottom of the page.
Now I want to change the apple image to a banana image, so I select the img first, and change the "src" attribute value to a new image address.
$("img").attr("src", "the new image address")
If I want to change the input type from text to color, I can write: $("input").attr("type", "color"). As the result, the input box changes to a color input.
.val()
According to jQuery, this method gets the current value of the first element in the set of matched elements or set the value of every matched element.
I type my name in the input, and then I call my name in the console by typing $("input").val().
If I want to update the input name, I can write the new name inside the val().
Comments
Post a Comment