How to add DOM elements in Jquery array and loop them? -
I'm trying to fix a problem for hours and I'm trying to search & amp; Code & amp; See that it works.
It may be better to explain the simple code that I am trying to do;
& lt; Script & gt; Test1 = $ ('input: text [name = test1]'); Test2 = $ ('input: text [name = test2]'); Test3 = $ ('input: text [name = test3]'); Var obj = []; Obj.push (test1); Obj.push (test2); Obj.push (test3); $ .each (obj, function (key, value) {console.log ('value:' + value.val ());}); & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Input name = "test1" type = "text" value = "1" /> & Lt; Input name = "test2" type = "text" value = "2" /> & Lt; Input name = "test3" type = "text" value = "3" /> & Lt; / Body & gt; & Lt; / Html & gt; What I'm trying to do;
- Define the variable that will be allocated to the DOM element.
- Create an array and insert the variables that are assigned to the DOM elements.
- Lapse them and get their prices etc ...
Is there any way to do this?
Thank you for your assistance and time in advance.
Edit: Of course, the above code was not trying to achieve anything. I have a form in which more than 700 lines are Jquery codes and I had a problem in my work.
The principle was the same, so I decided to understand something very little and clearly. $ Value just bad copy & amp; Paste it. Before I realized that I did not remove all my old code (just left $ ) and edited my post, some people responded already, it was not the right answer, But I did not want to stop the question without giving any marks to anyone. The above code will not work unless you change it;
$ (document) .ready (function () {// keep the code here}}; Considering my jquery code & lt; Head & gt; I hope this will help anyone.
I am not
Newbie in the jacquery, I do not know why and how I can make such a mistake.
Try this:
$ Each (obj, function () {console.log ('value:' + this.val ());})
Comments
Post a Comment