Reputation: 1704
I have a bunch of textboxes that are created dynamically one per click. They all have the same name "discount[]", same id "discount" and have the same class "tinput".
Is there anyway that I can use to change the text in all of these textboxes with javascript or jquery?
I have another bunch of the dynamically created text boxes. The id and name are unique but the class remains the same. If it gets the job done, I can change the class name.
Anyhelp is greatly appreciated.
Regards,
Upvotes: 0
Views: 881
Reputation: 32921
You definitely shouldn't use an id more than once per document. If you need it for a <label>
you might want to consider putting the input in the <label>
.
You are using the class
attribute the right way, though. You can do:
$('.tinput').val('New value for all .tinputs!');
If you can't put the input inside the label you can use use this. I made this demo for someone a little while ago. It might be helpful. It'll increment an id like "id-1".
http://jsbin.com/APegOMo/3/edit?html,js,output
Upvotes: 1
Reputation: 1591
here is a simple example that takes all elements with a particular class name and changes the .html, not 100% sure I understand what you're after though. if you need to do someting specific with each divs text you can iterate through them by id (and maybe class as well) and change each divs individual .html.
if you can share a stripped down example of your code or elaborate I'd love to try to help. good luck.
$(".changeDivs").html("adfasdf");
Upvotes: 0
Reputation: 2485
same id "discount"
Please, don't do that! "id" is to identify a dom element. That hurts in my soul. If every id is unique you could access them by $("#myid").val("my new val"). Just an example.
Regards, - Tobbo
Upvotes: 0