2

I have a page with a form, I'd like with a button have reset button effect only on input text inside a div here is an extraxt of my code:

html:

<div id="new_prom" style="clear:both; padding:2px; border:1px solid red; margin:5px;">
<div>
  Codice <input type="text" id="cod_pro" name="cod_pro" class="short"> Sottocodice <input type="text" id="sotto_pro" name="sotto_pro" class="short"><br>
Nominativo<br>
<input type="text" id="nom_pro" name="nom_pro" class="long">
</div>
<div>
<div class="bt" id="bt_pro">INSERISCI</div> <div class="bt" id="resetta">RESET</div>
</div>

jquery:

$("#resetta").live('click', function()
{
   $("#new_prom > text").each(function(){$(this).val("")});
});

thanks in advance.

ciao, h.

2 Answers 2

5

You almost have it correct, the selector is [type='text'] or :text, like this:

$("#resetta").live('click', function() {
  $("#new_prom :text").val("");
});

You can give it a try here, the other part is the .val(""), it'll work on all matched elements when setting, no need to loop in a .each().

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks to Nick Craver and Spinon that's working code for me: $("#resetta").live('click', function() { $("#new_prom :text").each(function(){$(this).val("")}); });
1

Think you forgot the colon.

$("#resetta").live('click', function() 
{ 
   $("#new_prom :text").each(function(){$(this).val("")}); 
});

2 Comments

I have tryed your code but not work in my case :( I've to say for understand better my problem that html and jquery codes are not in the same page
Yeah as @Nick mentioned I missed that the text elements are not direct children and didn't notice you had that. I was just fixing the text selector. So you need to remove the > sign like in my edit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.