Tuesday, 15 February 2011

Can I convert a form input string into the page background color with jquery? -



Can I convert a form input string into the page background color with jquery? -

i learning jqeury @ great pace codecademy.com, quality of it's lessons have declined point unusable. point me in direction of resources noobs larn sort of thing, or help me understand how themselves? thanks

you need break downwards want steps. want submit form first, go page before setting background colour? or want simple button that, 1 time clicked, changes background colour?

if latter, need perform following:

create form id "bg-form" , button within id "change" in jquery, check button beingness clicked using jquery's .click() within click function, value input field set background color, using css property, of value retrieved

your html:

<body> <form id="bg-form"> <input id="inp" type="text" name="colour"> <input id="change" type="submit" value="change colour"> </form> </body>

your jquery

$(document).ready(function(e) { // stops event of submitting form happening e.preventdefault(); // happens when alter button clicked $('#change').click(function() { // grab form text (here should perform empty checks) var colour = $('inp').val(); // either alter body, or div, or whatever, of value $("body").css("background-color", colour); }); });

note: it's american, create sure utilize background-color css property, , not "colour".

finally, suggestions, there's nothing improve jquery docs. contain loads of examples, , should seek things out individually see how work - that's how learn! jquery docs

jquery

No comments:

Post a Comment