How to use selector to get value under DOM using Jquery









up vote
1
down vote

favorite
1












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"










share|improve this question



















  • 9




    You have no .MainPart anywhere in your HTML.
    – CertainPerformance
    yesterday










  • @CertainPerformance is Mian .
    – 鄭名宏
    yesterday














up vote
1
down vote

favorite
1












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"










share|improve this question



















  • 9




    You have no .MainPart anywhere in your HTML.
    – CertainPerformance
    yesterday










  • @CertainPerformance is Mian .
    – 鄭名宏
    yesterday












up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





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"










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday

























asked yesterday









鄭名宏

206




206







  • 9




    You have no .MainPart anywhere in your HTML.
    – CertainPerformance
    yesterday










  • @CertainPerformance is Mian .
    – 鄭名宏
    yesterday












  • 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












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



  1. get every APart Class


  2. get APart DOM Data after to find next children class


  3. then we find it after just need use selector to find new class group






share|improve this answer




















  • thk u . I got it
    – 鄭名宏
    16 hours ago

















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.






share|improve this answer




















  • thk you, but I fix problem description.plz reconfirm
    – 鄭名宏
    yesterday

















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






share|improve this answer






















  • thk you, but I fix problem description.plz reconfirm
    – 鄭名宏
    yesterday

















up vote
1
down vote













U can use the each function for looping



$('.APart input[name="MainInput"]').each(function()
console.log($(this).val());
);





share|improve this answer




















  • thk you, but I fix problem description.plz reconfirm
    – 鄭名宏
    yesterday










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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



  1. get every APart Class


  2. get APart DOM Data after to find next children class


  3. then we find it after just need use selector to find new class group






share|improve this answer




















  • thk u . I got it
    – 鄭名宏
    16 hours ago














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



  1. get every APart Class


  2. get APart DOM Data after to find next children class


  3. then we find it after just need use selector to find new class group






share|improve this answer




















  • thk u . I got it
    – 鄭名宏
    16 hours ago












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



  1. get every APart Class


  2. get APart DOM Data after to find next children class


  3. then we find it after just need use selector to find new class group






share|improve this answer












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



  1. get every APart Class


  2. get APart DOM Data after to find next children class


  3. then we find it after just need use selector to find new class group







share|improve this answer












share|improve this answer



share|improve this answer










answered 16 hours ago









MingHong Zheng

958




958











  • thk u . I got it
    – 鄭名宏
    16 hours ago
















  • thk u . I got it
    – 鄭名宏
    16 hours ago















thk u . I got it
– 鄭名宏
16 hours ago




thk u . I got it
– 鄭名宏
16 hours ago












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.






share|improve this answer




















  • thk you, but I fix problem description.plz reconfirm
    – 鄭名宏
    yesterday














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.






share|improve this answer




















  • thk you, but I fix problem description.plz reconfirm
    – 鄭名宏
    yesterday












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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









Gary Thomas

713312




713312











  • 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




thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday










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






share|improve this answer






















  • thk you, but I fix problem description.plz reconfirm
    – 鄭名宏
    yesterday














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






share|improve this answer






















  • thk you, but I fix problem description.plz reconfirm
    – 鄭名宏
    yesterday












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






share|improve this answer














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







share|improve this answer














share|improve this answer



share|improve this answer








edited yesterday

























answered yesterday









Thirupathi cst

4219




4219











  • 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




thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday










up vote
1
down vote













U can use the each function for looping



$('.APart input[name="MainInput"]').each(function()
console.log($(this).val());
);





share|improve this answer




















  • thk you, but I fix problem description.plz reconfirm
    – 鄭名宏
    yesterday














up vote
1
down vote













U can use the each function for looping



$('.APart input[name="MainInput"]').each(function()
console.log($(this).val());
);





share|improve this answer




















  • thk you, but I fix problem description.plz reconfirm
    – 鄭名宏
    yesterday












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());
);





share|improve this answer












U can use the each function for looping



$('.APart input[name="MainInput"]').each(function()
console.log($(this).val());
);






share|improve this answer












share|improve this answer



share|improve this answer










answered yesterday









Faisal Mk

614




614











  • 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




thk you, but I fix problem description.plz reconfirm
– 鄭名宏
yesterday

















 

draft saved


draft discarded















































 


draft saved


draft discarded














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














































































這個網誌中的熱門文章

Is there any way to eliminate the singular point to solve this integral by hand or by approximations?

Why am i infinitely getting the same tweet with the Twitter Search API?

Solve: $(3xy-2ay^2)dx+(x^2-2axy)dy=0$