remove tag parent who contain a specific tag

jquery remove parent element
remove javascript
jquery remove element by id
jquery remove not working
jquery remove text
remove html element javascript
jquery find
jquery clear div content before append

I'm trying to delete all <p> who contains <br> tags. I'm using this jQuery code but it's wrong -- the code doesn't want delete br, I need to delete parent who have br.

need your help, I saw many remove script but it doesn't work.

jQuery(function($) {
  $('#singlecomment54').find('br').each(function() {
    $(this).remove();
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="singlecomment54" class="ql-container ql-disabled">

  <div class="ql-editor" data-gramm="false" contenteditable="false">
    <p>ghjkghjk</p>
    <p>GHJK</p>
    <p>GHJK</p>
    <p><br></p>
    <p><br></p>
  </div>

  <div class="ql-clipboard" contenteditable="true" tabindex="-1"></div>
</div>

You should be using .parent... as in :

$(this).parent('p').remove();

Code snippet:

jQuery(function($) {
  $('#singlecomment54').find('br').each(function() {
    $(this).parent('p').remove();
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="singlecomment54" class="ql-container ql-disabled">

  <div class="ql-editor" data-gramm="false" contenteditable="false">
    <p>ghjkghjk</p>
    <p>GHJK</p>
    <p>GHJK</p>
    <p>sdf<br></p>
    <p>sdf<br></p>
  </div>

  <div class="ql-clipboard" contenteditable="true" tabindex="-1"></div>
</div>

jQuery, Answer: Use the jQuery unwrap() method. Sometime you might require to remove the wrapper or parent element, a typical example is removing the anchor tag  Apply This Simple Home Remedy Before You Sleep And Your Skin Tags Dry Up And Fall Off. Get Rid Of All Unwanted Moles & Skin Tags. Safely-Quickly-Easily. *Get A Sample*

You're not removing the paragraph. You're removing the break tag itself:

jQuery(function($) {
    $('#singlecomment54').find('br').each(function() {
        $(this).remove();
    });
});
p:before { content: 'P: '; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="singlecomment54" class="ql-container ql-disabled">

   <div class="ql-editor" data-gramm="false" contenteditable="false"> 
   <p>ghjkghjk</p>
   <p>GHJK</p>
   <p>GHJK</p>
   <p><br></p>
   <p><br></p>
   </div>

   <div class="ql-clipboard" contenteditable="true" tabindex="-1"></div>
</div>

How can we delete specific child <div> inside the parent <div> tag , if you have this code for example div one div two div three you have may way to delete aby element by using removechild in javascript var  Try The Best Way To Remove Skin Tags At Home With A 100% Natural Formula. Tried & Tested Formula From Thousands of Satisfied Customers.

Try with this firts get all br tags Them get one level up parent "p" and remove it $("br").parent("p").remove ()

Or you can iterate the list of br objects an apply each item .parent ("p").remove()

.contents(), Given a jQuery object that represents a set of DOM elements, the .contents() method The few that do will have an explicit note on their API documentation page. Find all the text nodes inside a paragraph and wrap them with a bold tag. Remove the parents of the set of matched elements from the DOM, leaving the​  Special Offer for No Pain, No Scarring, No Chemicals, Say Goodbye to Unwanted Skin Tags. ALL NATURAL, PAIN-FREE WAY TO & Expertly Formulated to REMOVE Tag off skin tag remover

.remove(), Use .remove() when you want to remove the element itself, as well as everything inside it. Removes all paragraphs that contain "Hello" from the DOM. Best Skin Tag Removal Product On Shårk Tånk. Erase All Skin Tags In Hours! 547,150 Happy Users - Get Your Exclusive Discount Today! Click Here Now

jQuery Remove Elements, To remove elements and content, there are mainly two jQuery methods: remove() - Removes the selected element (and its child elements); empty() - Removes  This selects all elements, then uses .contents() to target the text content of the , then .unwrap() to remove its parent element. For the greatest performance, always go native: This will be much faster than any jQuery solution provided here.

Dreamweaver CS5.5: The Missing Manual, Don't try to remove the tag by hand in Code view: You have to change the code filter that lets you search and select XML elements that match certain criteria. This menu lists the repeating tag, its parent tag, its parent's parent tag, and so on​  How to select elements which do not have a specific child element with JQuery. Remove all element that does not have specific descendandt element in jquery-1.

Comments
  • <p> that contain solely <br/> tags, or <p> that contain <br /> tags mixed with other content too?
  • If that's all your .each() is doing, you could simplify your code down to $('#singlecomment54').find('br').parent('p').remove() or even $('#singlecomment54 p > br').parent().remove()
  • who thanks, not so far.. , I give you a +1 in few minues ( I can't for now )
  • @KeVin glad I could help. Please consider marking my answer as correct as well