Domanda

$('.questions input').iCheck({
     checkboxClass: 'icheckbox_line-blue',
     radioClass: 'iradio_line-blue',
     insert: '<div class="icheck_line-icon"></div>'
});

Using this approach does not fit to my needs:

$('.questions input').each(function () {

    var self = $(this),
    label = self.next(),
    label_text = label.text();

    label.remove();
    self.iCheck({
         checkboxClass: 'icheckbox_line-blue',
         transferClasses: true,
         radioClass: 'iradio_line-blue',
         insert: '<div class="icheck_line-icon"></div>' + label_text
    });

});

How do I retrive the current context ? I'd like to display the text which is between label tags. My html looks like

<div class="questions">
    <div class="question">
         <input type="checkbox" name="iCheck">
         <label>Question answer text</label>
    </div>
</div>
È stato utile?

Soluzione

Try this,

 $('.question input[type=checkbox]').each(function(){
    alert($(this).next('label').html());

});

Demo Here

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top