-1

I am working on sharepoint page. I dont have control html generate. so I am writing jquery for manupulation.

I am trying to change <h3> to <h1>. How to do that?

<tr>
    <td nowrap="true" valign="top" width="113px" class="ms-formlabel">
        <h3 class="ms-standardheader">
            <nobr>Thank you</nobr>
        </h3>
    </td>

I tried this

     $('table.ms-formtable > tbody > tr:nth-child(4) td:nth-child(1) h3').replaceWIth(function() {
            return $("<h1>", {
                "class", this.className,
                html: $(this).html();
            });
});

But did not work

Olivier De Meulder
  • 2,460
  • 3
  • 24
  • 29
James123
  • 9,918
  • 51
  • 172
  • 316

2 Answers2

1

Function names are case-sensitive (note replaceWIth vs. replaceWith):

$('table.ms-formtable > tbody > tr:nth-child(4) td:nth-child(1) h3').replaceWith(function() {
    return $('<h1>', {
        'class': this.className,
        'html':  this.innerHTML
    });
});

Also note that I have replaced the , after your class property with the correct colon (:) literal. Finally, you had a misplaced ; literal in the html definition of the return object. The above snippet should suffice and work as expected now.

jsFiddle Demo

BenM
  • 49,881
  • 23
  • 107
  • 158
0

You may need to first get the HTML and then replace by using JQuery Method replaceWith() it something like that:

var target = $('table.ms-formtable > tbody > tr:nth-child(4) td:nth-child(1) h3');
target.replaceWith($('<h1 class="'+target.attr('class')+'">' + target.innerHTML + '</h1>'));
hmd
  • 918
  • 2
  • 8
  • 12