0

I would like to know if a input type="checkbox" that comes just before a label is checked or not using javascript. The only thing I know is that the label has "Service Provider" in it

<input id="ctl00_ContentPlaceHolder1_UserTypeList_2" type="checkbox" name="ctl00$ContentPlaceHolder1$UserTypeList$2" />
<label for="ctl00_ContentPlaceHolder1_UserTypeList_2">Service Provider</label>

Tried this and failed.

$('label[text="Service Provider"]').prev().is(':checked')

What could I do?

Disclaimer: Its the markup rendered by ASP.NET 2.0 WebForms for a CheckBoxList

2 Answers 2

4

To search the text of an element, you need to use :contains().

$('label:contains("Service Provider")').prev().is(':checked')
Sign up to request clarification or add additional context in comments.

Comments

1

$("label:contains('Service Provider')").prev().is(':checked') should work

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.