How to use selector to get value under DOM using Jquery
up vote
1
down vote
favorite
I have a html container structure like as
<div class='APart'>
<div class='Main'>
<input name='MainInput' value='1'>
</div>
<div class='Sub'>
<input name='SubInput' value='2'>
<input name='SubInput' value='5'>
</div>
</div>
<div class='APart'>
<div class='Main'>
<input name='MainInput' value='3'>
</div>
<div class='Sub'>
<input name='SubInput' value='4'>
<input name='SubInput' value='6'>
</div>
</div>
and I using Jquery to do foreach and get data
$('.APart input[name=MainInput]').each(function(index, element)
console.log(this.value)
);
now I know how to get MainInput value,next step how to get SubInput value?
this is my expectation result
array[0] = "1,2,5"
array[1] = "3,4,6"
javascript jquery
add a comment |
up vote
1
down vote
favorite
I have a html container structure like as
<div class='APart'>
<div class='Main'>
<input name='MainInput' value='1'>
</div>
<div class='Sub'>
<input name='SubInput' value='2'>
<input name='SubInput' value='5'>
</div>
</div>
<div class='APart'>
<div class='Main'>
<input name='MainInput' value='3'>
</div>
<div class='Sub'>
<input name='SubInput' value='4'>
<input name='SubInput' value='6'>
</div>
</div>
and I using Jquery to do foreach and get data
$('.APart input[name=MainInput]').each(function(index, element)
console.log(this.value)
);
now I know how to get MainInput value,next step how to get SubInput value?
this is my expectation result
array[0] = "1,2,5"
array[1] = "3,4,6"
javascript jquery
9
You have no.MainPart
anywhere in your HTML.
– CertainPerformance
yesterday
@CertainPerformance is Mian .
– 鄭名宏
yesterday
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have a html container structure like as
<div class='APart'>
<div class='Main'>
<input name='MainInput' value='1'>
</div>
<div class='Sub'>
<input name='SubInput' value='2'>
<input name='SubInput' value='5'>
</div>
</div>
<div class='APart'>
<div class='Main'>
<input name='MainInput' value='3'>
</div>
<div class='Sub'>
<input name='SubInput' value='4'>
<input name='SubInput' value='6'>
</div>
</div>
and I using Jquery to do foreach and get data
$('.APart input[name=MainInput]').each(function(index, element)
console.log(this.value)
);
now I know how to get MainInput value,next step how to get SubInput value?
this is my expectation result
array[0] = "1,2,5"
array[1] = "3,4,6"
javascript jquery
I have a html container structure like as
<div class='APart'>
<div class='Main'>
<input name='MainInput' value='1'>
</div>
<div class='Sub'>
<input name='SubInput' value='2'>
<input name='SubInput' value='5'>
</div>
</div>
<div class='APart'>
<div class='Main'>
<input name='MainInput' value='3'>
</div>
<div class='Sub'>
<input name='SubInput' value='4'>
<input name='SubInput' value='6'>
</div>
</div>
and I using Jquery to do foreach and get data
$('.APart input[name=MainInput]').each(function(index, element)
console.log(this.value)
);
now I know how to get MainInput value,next step how to get SubInput value?
this is my expectation result
array[0] = "1,2,5"
array[1] = "3,4,6"
javascript jquery
javascript jquery
edited yesterday
asked yesterday
鄭名宏
206
206
9
You have no.MainPart
anywhere in your HTML.
– CertainPerformance
yesterday
@CertainPerformance is Mian .
– 鄭名宏
yesterday
add a comment |
9
You have no.MainPart
anywhere in your HTML.
– CertainPerformance
yesterday
@CertainPerformance is Mian .
– 鄭名宏
yesterday
9
9
You have no
.MainPart
anywhere in your HTML.– CertainPerformance
yesterday
You have no
.MainPart
anywhere in your HTML.– CertainPerformance
yesterday
@CertainPerformance is Mian .
– 鄭名宏
yesterday
@CertainPerformance is Mian .
– 鄭名宏
yesterday
add a comment |
4 Answers
4
active
oldest
votes
up vote
1
down vote
accepted
Add a new class tag on your input dom
<div class='APart'>
<div class='Main'>
<input class=''MainClass' name='MainInput' value='1'>
</div>
<div class='Sub'>
<input class=''SubClass' name='SubInput' value='2'>
<input class=''SubClass' name='SubInput' value='5'>
</div>
</div>
<div class='APart'>
<div class='Main'>
<input class=''MainClass' name='MainInput' value='3'>
</div>
<div class='Sub'>
<input class=''SubClass' name='SubInput' value='4'>
<input class=''SubClass' name='SubInput' value='6'>
</div>
</div>
so next step we can selector class like as
$('.APart').each(function(index, element)
$(this).children('.Main').find('.MainClass').each(function (i,e)
console.log($(e).val())
);
$(this).children('.Sub').find('.SubClass').each(function (i,e)
console.log($(e).val())
);
);
This code to do things
get every APart Class
get APart DOM Data after to find next children class
then we find it after just need use selector to find new class group
thk u . I got it
– 鄭名宏
16 hours ago
add a comment |
up vote
1
down vote
I think you meant MainInput
? You can select inputs via there name attribute, then get their value using the following:
$('.APart input[name=MainInput]').each(function(index, element)
console.log($(element).val());
);
Have a look at this CSS Selectors cheat sheet for more.
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
add a comment |
up vote
1
down vote
first give a class name for what your are accessing input
<div class='APart'>
<div class='Main'>
<input name='MainInput' value='1' class="getMain">
</div>
<div class='Sub'>
<input name='SubInput' value='2'>
</div>
<div class='Main'>
<input name='MainInput' value='3' class="getMain">
</div>
<div class='Sub'>
<input name='SubInput' value='4'>
</div>
</div>
after you can access with Jquery
$(':input.getMain').each(function(index, element)
var name = element.name;
);
reference
//this will give all your vaues
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
add a comment |
up vote
1
down vote
U can use the each function for looping
$('.APart input[name="MainInput"]').each(function()
console.log($(this).val());
);
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Add a new class tag on your input dom
<div class='APart'>
<div class='Main'>
<input class=''MainClass' name='MainInput' value='1'>
</div>
<div class='Sub'>
<input class=''SubClass' name='SubInput' value='2'>
<input class=''SubClass' name='SubInput' value='5'>
</div>
</div>
<div class='APart'>
<div class='Main'>
<input class=''MainClass' name='MainInput' value='3'>
</div>
<div class='Sub'>
<input class=''SubClass' name='SubInput' value='4'>
<input class=''SubClass' name='SubInput' value='6'>
</div>
</div>
so next step we can selector class like as
$('.APart').each(function(index, element)
$(this).children('.Main').find('.MainClass').each(function (i,e)
console.log($(e).val())
);
$(this).children('.Sub').find('.SubClass').each(function (i,e)
console.log($(e).val())
);
);
This code to do things
get every APart Class
get APart DOM Data after to find next children class
then we find it after just need use selector to find new class group
thk u . I got it
– 鄭名宏
16 hours ago
add a comment |
up vote
1
down vote
accepted
Add a new class tag on your input dom
<div class='APart'>
<div class='Main'>
<input class=''MainClass' name='MainInput' value='1'>
</div>
<div class='Sub'>
<input class=''SubClass' name='SubInput' value='2'>
<input class=''SubClass' name='SubInput' value='5'>
</div>
</div>
<div class='APart'>
<div class='Main'>
<input class=''MainClass' name='MainInput' value='3'>
</div>
<div class='Sub'>
<input class=''SubClass' name='SubInput' value='4'>
<input class=''SubClass' name='SubInput' value='6'>
</div>
</div>
so next step we can selector class like as
$('.APart').each(function(index, element)
$(this).children('.Main').find('.MainClass').each(function (i,e)
console.log($(e).val())
);
$(this).children('.Sub').find('.SubClass').each(function (i,e)
console.log($(e).val())
);
);
This code to do things
get every APart Class
get APart DOM Data after to find next children class
then we find it after just need use selector to find new class group
thk u . I got it
– 鄭名宏
16 hours ago
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Add a new class tag on your input dom
<div class='APart'>
<div class='Main'>
<input class=''MainClass' name='MainInput' value='1'>
</div>
<div class='Sub'>
<input class=''SubClass' name='SubInput' value='2'>
<input class=''SubClass' name='SubInput' value='5'>
</div>
</div>
<div class='APart'>
<div class='Main'>
<input class=''MainClass' name='MainInput' value='3'>
</div>
<div class='Sub'>
<input class=''SubClass' name='SubInput' value='4'>
<input class=''SubClass' name='SubInput' value='6'>
</div>
</div>
so next step we can selector class like as
$('.APart').each(function(index, element)
$(this).children('.Main').find('.MainClass').each(function (i,e)
console.log($(e).val())
);
$(this).children('.Sub').find('.SubClass').each(function (i,e)
console.log($(e).val())
);
);
This code to do things
get every APart Class
get APart DOM Data after to find next children class
then we find it after just need use selector to find new class group
Add a new class tag on your input dom
<div class='APart'>
<div class='Main'>
<input class=''MainClass' name='MainInput' value='1'>
</div>
<div class='Sub'>
<input class=''SubClass' name='SubInput' value='2'>
<input class=''SubClass' name='SubInput' value='5'>
</div>
</div>
<div class='APart'>
<div class='Main'>
<input class=''MainClass' name='MainInput' value='3'>
</div>
<div class='Sub'>
<input class=''SubClass' name='SubInput' value='4'>
<input class=''SubClass' name='SubInput' value='6'>
</div>
</div>
so next step we can selector class like as
$('.APart').each(function(index, element)
$(this).children('.Main').find('.MainClass').each(function (i,e)
console.log($(e).val())
);
$(this).children('.Sub').find('.SubClass').each(function (i,e)
console.log($(e).val())
);
);
This code to do things
get every APart Class
get APart DOM Data after to find next children class
then we find it after just need use selector to find new class group
answered 16 hours ago
MingHong Zheng
958
958
thk u . I got it
– 鄭名宏
16 hours ago
add a comment |
thk u . I got it
– 鄭名宏
16 hours ago
thk u . I got it
– 鄭名宏
16 hours ago
thk u . I got it
– 鄭名宏
16 hours ago
add a comment |
up vote
1
down vote
I think you meant MainInput
? You can select inputs via there name attribute, then get their value using the following:
$('.APart input[name=MainInput]').each(function(index, element)
console.log($(element).val());
);
Have a look at this CSS Selectors cheat sheet for more.
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
add a comment |
up vote
1
down vote
I think you meant MainInput
? You can select inputs via there name attribute, then get their value using the following:
$('.APart input[name=MainInput]').each(function(index, element)
console.log($(element).val());
);
Have a look at this CSS Selectors cheat sheet for more.
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
add a comment |
up vote
1
down vote
up vote
1
down vote
I think you meant MainInput
? You can select inputs via there name attribute, then get their value using the following:
$('.APart input[name=MainInput]').each(function(index, element)
console.log($(element).val());
);
Have a look at this CSS Selectors cheat sheet for more.
I think you meant MainInput
? You can select inputs via there name attribute, then get their value using the following:
$('.APart input[name=MainInput]').each(function(index, element)
console.log($(element).val());
);
Have a look at this CSS Selectors cheat sheet for more.
answered yesterday
Gary Thomas
713312
713312
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
add a comment |
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
add a comment |
up vote
1
down vote
first give a class name for what your are accessing input
<div class='APart'>
<div class='Main'>
<input name='MainInput' value='1' class="getMain">
</div>
<div class='Sub'>
<input name='SubInput' value='2'>
</div>
<div class='Main'>
<input name='MainInput' value='3' class="getMain">
</div>
<div class='Sub'>
<input name='SubInput' value='4'>
</div>
</div>
after you can access with Jquery
$(':input.getMain').each(function(index, element)
var name = element.name;
);
reference
//this will give all your vaues
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
add a comment |
up vote
1
down vote
first give a class name for what your are accessing input
<div class='APart'>
<div class='Main'>
<input name='MainInput' value='1' class="getMain">
</div>
<div class='Sub'>
<input name='SubInput' value='2'>
</div>
<div class='Main'>
<input name='MainInput' value='3' class="getMain">
</div>
<div class='Sub'>
<input name='SubInput' value='4'>
</div>
</div>
after you can access with Jquery
$(':input.getMain').each(function(index, element)
var name = element.name;
);
reference
//this will give all your vaues
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
add a comment |
up vote
1
down vote
up vote
1
down vote
first give a class name for what your are accessing input
<div class='APart'>
<div class='Main'>
<input name='MainInput' value='1' class="getMain">
</div>
<div class='Sub'>
<input name='SubInput' value='2'>
</div>
<div class='Main'>
<input name='MainInput' value='3' class="getMain">
</div>
<div class='Sub'>
<input name='SubInput' value='4'>
</div>
</div>
after you can access with Jquery
$(':input.getMain').each(function(index, element)
var name = element.name;
);
reference
//this will give all your vaues
first give a class name for what your are accessing input
<div class='APart'>
<div class='Main'>
<input name='MainInput' value='1' class="getMain">
</div>
<div class='Sub'>
<input name='SubInput' value='2'>
</div>
<div class='Main'>
<input name='MainInput' value='3' class="getMain">
</div>
<div class='Sub'>
<input name='SubInput' value='4'>
</div>
</div>
after you can access with Jquery
$(':input.getMain').each(function(index, element)
var name = element.name;
);
reference
//this will give all your vaues
edited yesterday
answered yesterday
Thirupathi cst
4219
4219
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
add a comment |
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
add a comment |
up vote
1
down vote
U can use the each function for looping
$('.APart input[name="MainInput"]').each(function()
console.log($(this).val());
);
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
add a comment |
up vote
1
down vote
U can use the each function for looping
$('.APart input[name="MainInput"]').each(function()
console.log($(this).val());
);
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
add a comment |
up vote
1
down vote
up vote
1
down vote
U can use the each function for looping
$('.APart input[name="MainInput"]').each(function()
console.log($(this).val());
);
U can use the each function for looping
$('.APart input[name="MainInput"]').each(function()
console.log($(this).val());
);
answered yesterday
Faisal Mk
614
614
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
add a comment |
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222184%2fhow-to-use-selector-to-get-value-under-dom-using-jquery%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
9
You have no
.MainPart
anywhere in your HTML.– CertainPerformance
yesterday
@CertainPerformance is Mian .
– 鄭名宏
yesterday