Hi,

I understand the fundamental of replacing from a <div> to a <button>.
i am having trouble though adding an id to the replacement.

example>
say i have the following code:

<div class="container">
  <div class="inner first">Hello</div>
  <div class="inner second">And</div>
  <div class="inner third">Goodbye</div>
</div>

I am applying this jquery to replace
<div class="inner first">Hello</div> with <button id="myBtn" class="btn">Hello</button>

<script>
$( "div.first" ).replaceWith( "<button id="myBtn" class="btn">Hello</button>" );
</script>

but it doesn't seem to work right. any help?

Member Avatar for diafol

You need to escape the double quotes around the ID with a backslash or use single quotes instead. Same with class.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.