tags:

views:

33

answers:

3

I want to locate a div and replace both the content and div class name with another, how to do that

<div class="replaceme1"> 
  replace me 2, too
+6  A: 
$("div.replaceme1")
    .html("<p>new text</p>")
    .removeClass("replaceme1")
    .addClass("SomeNewClassReplacement");
Alexander
A: 
$('div.replaceme1')
    .removeClass('replaceme1')
    .addClass('Foo')
    .html('<p>Some new text</p>')

Have a read of .html(), .removeClass() and .addClass()

Evil Andy
+1  A: 

Assuming you use the jQuery library, check out:

  1. The .text() or .html() attribute to modify it's content;
  2. The .addClass() and .removeClass() attribute; or
  3. The .attr() attribute;

to modify it's class. Note that the latter will require you to use quotes.

So, for your example, you would do:

$('div.replaceme1')
    .removeClass('BottomSmMargin MiniCheckDiv')
    .text('Hello world!');
Soravux