0
<li id="sub:777" class="jstree-leaf">
    <ins class="jstree-icon2">&nbsp;</ins>
    <a class=""><ins class="jstree-icon2">&nbsp;</ins>Story B</a>
</li>

I need to change the class of the <ins> tags for a specific <li>:

 var original_sub_id = $j(element).attr('id'); e.g sub:777
 var new_sub_id = original_sub_id.split(":");
 new_sub_id = new_sub_id.join("\\\\:"); e.g sub\\:777

I need to pass the new_sub_id variable in the code below, but it does not seem to work:

$j("#"+new_sub_id + "ins:eq(1)").attr("class","jstree-icon2"); // set class to display new icon

Any suggestion are most welcome.

3
  • can you clarify what you mean by "I need to change the class of the tags for a specific"? Commented Nov 3, 2011 at 17:27
  • i need to change the class of the <ins> tags for a specific <li> tag. Commented Nov 3, 2011 at 17:28
  • You need to put a space between new_sub_id and "ins:eq(1)" Commented Nov 3, 2011 at 17:28

3 Answers 3

1

i have a feeling it's because of the : in your ID.

: in jquery selectors tends to preceed a pseudo selector like :checked, :selected, :focus

Sign up to request clarification or add additional context in comments.

3 Comments

That's why they're escaping the : with \\
those id's are coming from a DB? do you need to use them to post back? you could probably do some fancy string replacing and swap the : for a -, and then swap it back when you need to send it to the server. with out seeing more of your code it's hard to say exactly how to fix it.
Yes, those ids come from the db and i need to post them back.I replaced the colon with some other char and stored it in a var and then i swapped it back when saving it to the db. Thanks for the suggestion :)
1
$j("#"+new_sub_id + " ins:eq(1)").attr("class","jstree-icon2"); // set class to display new icon

Don't forget the space before ins:eq(1)

Also be sure this element exists : $j("#"+new_sub_id + " ins:eq(1)")

1 Comment

It's still not working, even if i put the space before ins. If i put: $j("#sub\\:7428 ins:eq(1)").attr("class","jstree-icon2"); it works fine.
0

Since you already have a reference to the li, you can just pass that as the context for your selector.

$j("ins:eq(1)", element).attr("class","jstree-icon2")

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.