Created
April 23, 2011 00:24
-
-
Save spartanp/938013 to your computer and use it in GitHub Desktop.
set() vs setAttribute()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <h2> tests using setAttribute() method </h2> | |
| <div> | |
| <input id="p" value="setAttribute() Test"> | |
| <button id="csa"> Clear value using setAttribute() method </button> | |
| <button id="sa"> Set the default value back using setAttribute method </button> | |
| </div> | |
| <h2> tests using set() method </h2> | |
| <div> | |
| <input id="pv" value="set() test"> | |
| <button id="csv"> Clear value using set() method </button> | |
| <button id="sv"> Set the default value using set() method </button> | |
| </div> | |
| <script src="http://yui.yahooapis.com/3.3.0/build/yui/yui.js" charset="utf-8"></script> | |
| <script> | |
| YUI({"filter": "raw"}).use("event", "node", function(Y) { | |
| var i = Y.one("#p"), | |
| iv = Y.one("#pv"); | |
| // setAttribute | |
| Y.on("click", function(e) { | |
| i.setAttribute("value", ""); | |
| }, "#csa"); | |
| Y.on("click", function(e) { | |
| var defaultVal = i.get("defaultValue"); | |
| Y.log("setAttribute() test default value is: " + defaultVal); | |
| i.setAttribute("value", defaultVal); | |
| }, "#sa"); | |
| // set | |
| Y.on("click", function(e) { | |
| iv.set("value", ""); | |
| }, "#csv"); | |
| Y.on("click", function(e) { | |
| var defaultVal = iv.get("defaultValue"); | |
| Y.log(" set() test default value is: " + defaultVal); | |
| iv.set("value", defaultVal); | |
| }, "#sv"); | |
| }); | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <h2> tests using setAttribute() method </h2> | |
| <div> | |
| <input id="p" value="setAttribute() Test"> | |
| <button id="csa"> Clear value using setAttribute() method </button> | |
| <button id="sa"> Set the default value back using setAttribute method </button> | |
| </div> | |
| <h2> tests using set() method </h2> | |
| <div> | |
| <input id="pv" value="set() test"> | |
| <button id="csv"> Clear value using set() method </button> | |
| <button id="sv"> Set the default value using set() method </button> | |
| </div> | |
| <script src="http://yui.yahooapis.com/3.3.0/build/yui/yui.js" charset="utf-8"></script> | |
| <script> | |
| YUI({"filter": "raw"}).use("event", "node", function(Y) { | |
| var i = Y.one("#p"), | |
| iv = Y.one("#pv"); | |
| // setAttribute | |
| Y.on("click", function(e) { | |
| i.setAttribute("value", ""); | |
| }, "#csa"); | |
| Y.on("click", function(e) { | |
| var defaultVal = i.get("defaultValue"); | |
| Y.log("setAttribute() test default value is: " + defaultVal); | |
| i.setAttribute("value", defaultVal); | |
| }, "#sa"); | |
| // set | |
| Y.on("click", function(e) { | |
| iv.set("value", ""); | |
| }, "#csv"); | |
| Y.on("click", function(e) { | |
| var defaultVal = iv.get("defaultValue"); | |
| Y.log(" set() test default value is: " + defaultVal); | |
| iv.set("value", defaultVal); | |
| }, "#sv"); | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment