-1

I want change part two of class name in each div into tag <span> from '.myclass_2' to 'yourclass', (in following html code). Here is my try with jQuery but they doesn't work true. How is fix it?

Demo: http://jsfiddle.net/sTF3U/

<span>
    <div class="myclass_1 myclass_2">
        <a href="" class="click">Click Me_1</a>
    </div>
    <div class="myclass_1 myclass_2">
        <a href="" class="click">Click Me_2</a>
    </div>
</span>




var $this = $('.click'),
    $clone_1 = $('span').clone();
    alert($clone_1.html());

$('.click').live('click', function (e) {
    e.preventDefault();   

    $clone_2 = $('span').clone();

    $clone_2.find('div').split(" ")[1].addClass('youClass');

    $clone.find('.auto_box2:last .mediumCell').each(function () {
        $(this).split(" ")[1].removeClass().addClass(unique());
    });

    var $result = $('span').clone();
    alert('ok');
})
3
  • Putting <div> elements inside <span> elements doesn't really make much sense. A <span> is for inline content.
    – Pointy
    Nov 28, 2011 at 17:05
  • 1
    Also that code is clearly incorrect, but it's so incorrect that I can't tell even what it's intended to do. Can you describe what it is that the "click" events should do to the markup?
    – Pointy
    Nov 28, 2011 at 17:07
  • can you add how you expect the document to look after the edit has been applied? i can't make much from your question text but if i have a target...
    – Kris
    Nov 28, 2011 at 17:08

3 Answers 3

2

Try this:

$("div.myclass_2").removeClass("myclass_2").addClass("yourclass");

BTW, a <div> inside a <span> is not valid HTML.

2

Juse use removeClass passing the required class to remove and then use addClass passing the required class to add to any element. Try this

$(".myclass_2").removeClass("myclass_2").addClass("yourclass");
1

Use jquery removeClass and addClass method to remove the existing class and then add the renamed class

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.