I want to set my variable to the value of my num1 text box. What am I doing wrong with this?
aa = $("#num1").val(); alert(aa); //var bb = document.getElementById('num1').value; //alert(bb);
here is the whole code http://jsfiddle.net/EmRLE/
<!DOCTYPE html> <html> <head> <style> #box { font-family:Arial; float:right; background: blue; color: orange; width:200px; height: 200px; padding:10px; margin: 10px; border : 10px solid gray; } </style> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script> $(document).ready(function(){ $("#a").click(function(){ alert("Background color = " + $("div").css("background-color") + " " + "\nfont is " + $("div").css("font-family") + " \nFloat property is " + $("div").css("float") + " " + " \ncolor of the text is " + $("div").css("color") + " " + "\nthe width is " + $("div").css("width") + " " + + $("div").css("width") + " " + " \nthe height is " + $("div").css("height") + " " + "\nthe margin is " + $("div").css("margin") + " " + "\n the padding is " + $("div").css("padding") + "."); }); $("#b").click(function(){ aa = $("#num1").val(); alert(aa); </script> </head> <body> <div id="box">My Div</div> <button id = "a" >Display CSS Values </button><br><br><br> <button id = "b" >Enter height value: </button><input type="text" name="num1" /> <br><br><br> <button id = "c" >Enter background color: </button><input type="text" name="num2" /> </body> </html>
source share