tags:

views:

46

answers:

3

Do to an IE6 bug I need to alter some Jquery,

I want to take an element called #nav, append to the ID.

I already use addClass to create <div id="#nav" class="test">

$('span .breadcrumb').each(function(){
    $('#Nav').addClass($(this).text());

Which takes the breadcrumb navigation text and adds it as a new class to the

Can i use .append to add the text to the ID?

+4  A: 

Just change the id attribute:

$('#nav').attr('id','nav' + appendString);

Where appendString contains whatever you want to append.

Karl B
And I'm assuming that the HTML is really <div id="nav" class="test"> - without an invalid leading # on the id.
Karl B
+1  A: 

It should work.

$(this).attr('id', $(this).attr('id') + $(this).text() );

Or whatever you need to do.

Stefan Kendall
I initially thought this would be the way to go. However, the OP already knows the ID of the element, so there's no need to get the ID again.
S Pangborn
This is a more general answer that will apply in more situations.
Stefan Kendall
A: 

Append adds to the content of the element, not its attributes. To do what you're after, I'd use the following:

$('#nav').attr('id', 'nav' + 'appendedString');
S Pangborn