-1

I have a section of code which I don't have full control over which includes a Div with no class or id. I'd like to remove the opening and closing tag of this Div and keep the existing content, but not sure how to target this and remove ?

currently...

<li id="foo" class="underline">

<div>
<input id="username" name="username" required="required" class="validate" type="text">
</div>

<label for="username">Username</label>

</li>

the final result i would like...

<li id="foo" class="underline">

<div class="mynewdiv">

<input id="bar" name="bar" required="required" class="validate" type="text">
<label for="bar">Username</label>

</div>

</li>

I have control to add teh newDiv. My question has similarities to how can I remove wrapper (parent) without removing the child but i'm not sure how to properly target this unnamed div (with closest?). Thanks

Paul Smith
  • 43
  • 7
  • 1
    I'm voting to close this question as off-topic because SO is here to help with code you wrote but SO is not here to write code for you. – Rob Jun 14 '17 at 12:21
  • Why can't you just give the `
    ` an id or remove the `
    ` from the html? Does this have to be a change at run time?
    – Tim Hutchison Jun 14 '17 at 12:35
  • I don't have full control over the code in the framework to change the
    . Many thanks to Carsten for his answer. Sorry I didn't think my code attempts that good to be worth adding.
    – Paul Smith Jun 14 '17 at 15:03

1 Answers1

0

You can use .append() on your div and inside that find the label

$(".underline div").append(function(){
  return $(this).next("label");
}).addClass("mynewdiv");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li id="foo" class="underline">

  <div>
    <input id="username" name="username" required="required" class="validate" type="text">
  </div>

  <label for="username">Username</label>

</li>
Carsten Løvbo Andersen
  • 26,637
  • 10
  • 47
  • 77