Home >Web Front-end >JS Tutorial >Native js implements the result of changing the name and value of the div attribute style at will_javascript skills

Native js implements the result of changing the name and value of the div attribute style at will_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:21:081462browse

Some simple examples use native js and jQuery to change div attributes and reset them at will. The code is as follows:

Copy code The code is as follows:





Function passes parameters to change the value of any attribute of Div












Enter "attribute name" in the upper input box and "Attribute Value", click the OK button to view the effect.




$(function(){
$("button:first").click(function() {
var styleName= $("#outer").find("input:first").val();
var styleVal = $("#outer").find("input:last") .val();
$("#div1").css(styleName,styleVal);
})
$("button:last").click(function(){
$ ("#div1").removeAttr("style");
})
})




< ;body>





Enter "attribute name" and "attribute value" in the upper input box, and click the OK button to view the effect.




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn