1

Well.... i've the next problem and i don't know for why....

I need clear some inputs, the value and text but the text in the input not clear.

My code:

$("#bloque-addDireccion").each(function(){
      var input = $(this).find("input[name$='Mia']");
      $(input).each(function(){
          $(this).text("");
          $(this).attr("value","");
      });              
});

I'm inspect the inputs and the value it's correct ("") but i've the older text always in the input.

What i'm do wrong?

Govind Singh
  • 15,282
  • 14
  • 72
  • 106
Marcos
  • 241
  • 5
  • 13

3 Answers3

6

The .text(text) method cannot be used on form inputs. To set the text value of input or textarea elements, use the .val(value) method.

please also check the Difference between val() and text()

try .val(value)

 $(this).val("");
Community
  • 1
  • 1
Govind Singh
  • 15,282
  • 14
  • 72
  • 106
1

As others mentioned to change the value you need to do $(this).val("");. Me being a beginner as well, my guess why .text() does not work is because as mentioned here: http://www.w3schools.com/tags/tag_input.asp, <input> does not have a text attribute, therefore at this example, $(this).text() seems to point at nothing.

hahaha
  • 1,001
  • 1
  • 16
  • 32
0

Well... My solution: I chage the value in other javascript using .value("xxxxx"); to change the value and I change this for

.attr("value","xxxx");

And, when I try to reset/change next time the value, i'm using

.attr("value","xxxx");

and it's works....If put .val("xxx"); isn't works!

Thanks for all responses! :D

Marcos
  • 241
  • 5
  • 13