0

This is my codepen: http://codepen.io/JTBennett/pen/OpEeBG

This is the jQuery in question:

  $('.gvListing').each(function(){
    var cntTxt = $('.dispCntry').text()
    $(this).attr('data-country',cntTxt)
  var valueC = $('.ddCountry:selected').val();
  var valueR = $('.ddRegion:selected').val();
  $('#testDiv').text(valueC)
  });

(^this all happens at the bottom of the JS on the codepen link)

The issue looks like this:

enter image description here

So the data attribute is being filled up with every .dispCntry div's contents even though I'm doing this function in .each() .gvListing div. I have a feeling I'm missing something stupid, like the letter i somewhere - but I can't seem to get it right.

1
  • I ran your Codepen and inpected the elements... I just can see where this happens. Commented Mar 25, 2017 at 3:08

1 Answer 1

2

var cntText=$('.dispCntry').text(); will take every text of input that has .dispCntry class. It does not concentrate on your .each() .gvListing div. Either you have to use only one .dispCntry class input, or give unique class or id to each .dispCntry elements

Sign up to request clarification or add additional context in comments.

2 Comments

OK maybe I've had the wrong idea about what .each does exactly :}. I'm hoping maybe I can assign an attribute value to each of the listing divs - maybe I can do that right when the strings are being called for the first time?
I'll try .each('listing') -> .find('nearest country field') -> .attr(this) --- does that sound plausible?

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.