2

I have a repeater and have a label with an icon inside it.

 <strong><i id="iconProperties" class="icon-caret-right"></i>&nbsp;Properties</strong>

When i click a button the icon-caret-right must be turned to icon-caret-down. i have written the code as follows:

 $('#iconProperties').removeClass('icon-caret-right').addClass('icon-caret-down');

When i use this code only the first row of the repeater is working. all other rows's icons are not changing. What is the mistake?

3
  • Are you using the same id on multiple elements? Commented Dec 17, 2013 at 6:03
  • same id in the sense??? i am using repeater. Commented Dec 17, 2013 at 6:04
  • As in id="iconProperties". Are there multiple elements that have the exact same id in the generated HTML code that are sent to the browser? Commented Dec 17, 2013 at 6:07

3 Answers 3

4

ASP.net generates unique ids for html elements and only one element can have id iconProperties that you used in selector. You can use Attribute Contains Selector [name*="value"] instead of id selector to get all the matching elements.

$('[id*=iconProperties]').removeClass('icon-caret-right').addClass('icon-caret-down');
Sign up to request clarification or add additional context in comments.

4 Comments

ya. this will work. but anyone can plz explain the diff between [id*=iconProperties] and [id^=iconProperties] to understand better.
id* is for contains and id^ is for starts with
How to find the same element using document.getelementbyid instead of $ ?
This will give you an idea, stackoverflow.com/questions/17452205/…
3

If your ids have a similar name, you're probably after something like $('[id^=iconProperties]').removeClass('icon-caret-right').addClass('icon-caret-down');
Which will update all items beginning with id "iconProperties".

It might be worth noting that it is common practice to use unique ids.

Comments

1

Try this:

$('#iconProperties').find('.icon-caret-right').replaceWith('.icon-caret-down');

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.