1

Based on the manual as follows:

http://api.jquery.com/attr/ 
attr( attributeName, value ) 

I should be able to replace the attribute value of a selected element.

             <div id="keynote1Fld" class="row ">
                <label for="keynote1" class="labeloptional">Topic 1</label>
                <div class="collection">
                 <input type="text" class="largetextfield" maxlength="96" size="96" value="" id="keynote1" name="keynote1" />
                </div>
             </div>

I need to replace the class value of label for keynote1 from labeloptional to label.

Here is what have done:

$("label[for=keynote1]").att('class', 'label');

However, the class value for label of keynote1 still is 'labeloptional' after the execution of the above statement.

why?

Thank you

1 Answer 1

7

You need to use attr not att.


However, if you're changing classes, you shouldn't be using attr().

What you should do is use removeClass() and addClass().

$('label').removeClass('oldClass').addClass('newClass');

That way, you won't be overwriting any other classes that might be assigned to a tag.

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

1 Comment

More specifically: $('label[for=keynote1]').attr('class', 'label');

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.