0

I'm trying to get all labels with an attribute of "selected" without a null or empty value. I can't seem to find any labels. Here is the html.

<form id="frmPickGames">
    <div style="margin-top: 150px">
    <div data-bind="foreach: games, visible: games().length > 0">
        <div class="row clearRight borderBottom">
            <div class="col-sm-12 col-md-12 col-lg-12">
                <label class="" data-bind="text: gameDate"></label> / Time:
                <label class="" data-bind="text: gameTimeET"></label> / Tv Station:
                <label class="" data-bind="text: tvStation"></label>
            </div>
            <div id="mode-group" class="btn-group btn-group-lg btn-group-justified" data-toggle="buttons">
                <div class="col-sm-12 col-md-4 col-lg-4 text-center awayColumn">
                    <label class="btn btn-default" data-bind="click: $parent.save, attr: { id: gameId() + '~' + awayTeam(), selected: teamId() }">
                        <input type="radio" data-bind="attr: { name: gameId(), id: gameId() + '~' + awayTeam() }" selected >
                        <img data-bind="attr: { src: awayTeamLogoUrl, alt: awayTeamFullName }" style="height: 100px; width: 150px;" /><br />
                        <label data-bind="text: awayTeamFullName"></label>
                    </label>
                </div>
                <div class="col-sm-12 col-md-2 col-lg-2 text-center" style="padding-top: 50px;">AT</div>
                <div class="col-sm-12 col-md-4 col-lg-4 text-center homeColumn">
                    <label class="btn btn-default" data-bind="click: $parent.save, attr: { id: gameId() + '~' + homeTeam() }">
                        <input type="radio" data-bind="attr: { name: gameId(), id: gameId() + '~' + homeTeam() } ">
                        <img data-bind="attr: { src: homeTeamLogoUrl, alt: homeTeamFullName }" style="height: 100px; width: 150px;" /><br />
                        <label data-bind="text: homeTeamFullName"></label>
                    </label>
                </div>
            </div>
        </div>
    </div>
    </div>
</form>

Here is the javascript/jquery that I'm trying to use to get all the labels so that I can set a class to show that the label was selected. I'm assuming this doesn't work because the labels are too deep in the html code.

$('label[selected!=""]').each(function () {
    alert('hi');

});
1
  • Do you want the label or the radio button with selected? Because from your code, the label tags have selected inside the data-bind element Commented Feb 24, 2015 at 16:37

2 Answers 2

2

If you wanna find the label that contains 'selected' in the 'data-bind'attribute, just use this selector:

$("label[data-bind*='selected']").each(function () {
    alert('hi');
});
Sign up to request clarification or add additional context in comments.

3 Comments

please see my edit, the alert is never being called.
Are you trying to get the labels that contains selected attr inside the data-bind? (Ex.: <label class="btn btn-default" data-bind="click: $parent.save, attr: { id: gameId() + '~' + awayTeam(), selected: teamId() }">... Or are you trying to get elements with selected attribute like: <input type="radio" data-bind="attr: { name: gameId(), id: gameId() + '~' + awayTeam() }" selected >?
I'm trying to get (<label class="btn btn-default" data-bind="click: $parent.save, attr: { id: gameId() + '~' + awayTeam(), selected: teamId() }"> )
0

It sounds like

$('label').each(function () {
    if($(this).find('input[selected]').size()){
        alert('hi');
    }
});

to find all the labels that have an input that is 'selected'

Comments

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.