0

I'm am dynamically creating elements with class "gmapItems". And I need to export an array of these elements for each.

Any ideas?

HTML:

<div class="gmapItems">
<input type="text" class="input-medium googleMapCity" value='1'>
<input type="text" class="input-medium googleMapAddress" value='1'>
<textarea class="input-medium googleMapInformation" value='1'></textarea>
</div>

<div class="gmapItems">
<input type="text" class="input-medium googleMapCity" value='2'>
<input type="text" class="input-medium googleMapAddress" value='2'>
<textarea class="input-medium googleMapInformation" value='2'></textarea>
</div>

Jquery:

    $("#AddGoogleMap").on('click', function () {            
    mapMarkers = new Array();
    $('.gmapItems').each(function(){
    gmapCity = $('.googleMapCity').val();
    gmapAddress = $('.googleMapAddress').val();
    gmapInfo = $('.googleMapInformation').val();  
    mapMarkers.push(gmapCity, gmapAddress, gmapInfo); 
    alert(mapMarkers)
    });
1
  • is there a push for multiple value ? mapMarkers.push(gmapCity, gmapAddress, gmapInfo); Commented May 16, 2013 at 9:22

1 Answer 1

1

Try this : You need to use this in $('.googleMapCity',this).val() to get .googleMapCity inside of current .gmapItems

$("#AddGoogleMap").on('click', function () {            
var mapMarkers = $('.gmapItems').map(function(){
       mapMarker = new Array();
       mapMarker.push($('.googleMapCity',this).val());
       mapMarker.push($('.googleMapAddress',this).val());
       mapMarker.push($('.googleMapInformation',this).val());  
       return mapMarker;
    }).get();
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for "this"! "This" made it all!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.