Alex Rivera | Logout

How do you select all id tags that contain a certain string in javascript?

Asked 2011-11-14T18:23:13.410
19

I have an ASP.NET application that renders multiple questions with the option to provide an explanation for the answers given.

<label for="[<%:count %>].AnswerExplanation_<%: i+1 %>" id="[<%:count %>].toggleExplanation_<%: i+1 %>"><strong>Add Explanation</strong></label>
<br /><br />
<div id="[<%:count %>].Explanation_<%: i+1 %>">
    <textarea id="[<%:count %>].AnswerExplanation_<%: i+1 %>" name="[<%:count %>].AnswerExplanation_<%: i+1 %>" class="ckedit"></textarea>
</div>

so you will have id's like "[X].toggleExplanation_Y" corresponding to "[X].AnswerExplanation_Y"

I am writing a javascript function to show/hide the AnswerExplanation divs, and was looking for a way to select every id containing "toggleExplanation" I should be able to get the rest from there.

Edit
Report

1 Answer

1

Give all the .toggleExplanation_ divs a unique marker CSS class. Then you can simply use jQuery to select all elements with that class.

answered 2011-11-14T18:28:26.823

Your Answer