1

I have an issue with using multiple values in a data tag, and applying a filter based on the id of this. because its showing multiple ids in the data tag it wont show both ids.

Example at http://jsfiddle.net/rWhVN/

<script type="text/javascript">
        $(function () {
            $('#content').removeClass('nojs');
            $('.row').not('#q1').hide();
            $('select').on('change', function () {
                var question = $(this).parent().parent().attr('id');
                var answerID = $(this).children('option:selected').attr('id');
                var loadQuestion = $(this).children('option:selected').data('load');
                $('#' + question).addClass('answered');
                $('.row').not('.answered').hide();
                $('#' + loadQuestion).fadeIn();
                console.log(loadQuestion);
            });
        });
    </script>

<option id="q1a1" data-load="q2, q8">Answer 1</option>

Question one answer one should show question two and question eight.

Not sure how you split this out, so any help appreciated.

1 Answer 1

1

$('#' + loadQuestion) will be $('#q2, q8'), which will not be the seletor for #q2 and #q8.

You could do data-load="#q2, #q8", and then just do $(loadQuestion).

See the demo.

And if you can't change the data-load attribute, then you could do with:

$($.map(loadQuestion.split(/ *, */), function(el) {return '#'+el;}).join(',')).fadeIn();
Sign up to request clarification or add additional context in comments.

1 Comment

thats really helpful, I haven't looked at the map feature yet so thanks very much for your help

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.