0

I am creating an A/B test variant using VWO. The website has a list with checkboxes laid out like so;

<ol>
    <li>
        <label>
            <input class="checkBox" type="checkbox">
            <p class="checkBoxAnc">Text to grab</p>
        </label>
    </li>
</ol>

There is an apply button, when this is clicked I want it to cycle through all of the inputs. If checked is true then I need to grab the text from the class "checkBoxAnc" (p element) and concatenate it to a variable.

I have tried the following:

var self= $(this);
//This is referring to the input that the user has clicked, so class '.checkBox'

self.next() // This doesn't work as element's do not match

self.nextUntil('.checkBoxAnc') // Same issue as .next()

var checkBoxSibling = self.parent().find('.checkBoxAnc').text();
// This returns an empty string

When trying to find the parent type this is being returned as 'undefined' rather than 'label'

Are there any other techniques to access '.checkBoxAnc'?

GrapeSoda
  • 131
  • 4
  • 1
    [Works for me](https://jsfiddle.net/tu4tv5kq/). If you're having an issue, you need to provide a *complete yet minimal* demonstration that actually represents the issue. –  Aug 05 '16 at 14:46
  • 1
    Works here as expected using `next()` - https://jsfiddle.net/9vfyez40/ - try giving us a [mcve] – Jamiec Aug 05 '16 at 14:47

1 Answers1

0

Something like this...

var foo = '';

$('input[type=checkbox]:checked').map(function() {
    foo += $(this).next().text(); // value your looking for
}).get();

https://jsfiddle.net/cmac_/8w7vghbt/

cmac
  • 3,123
  • 6
  • 36
  • 49