How to wrap HTML text in each new line with <li> tag?

Adnan Jamil

I have this code:

<aside id="jmfe_widget-2" class="widget widget-job_listing widget_jmfe_widget">

    <h2 class="widget-title widget-title-job_listing %s">Amenities</h2>

    Air conditioning<br>
    Free parking<br>
    Access to bathrooms<br>
    Loading dock<br>
    Elevator<br>

</aside>

I want to wrap these points as list items, like this:

<aside id="jmfe_widget-2" class="widget widget-job_listing widget_jmfe_widget">

    <h2 class="widget-title widget-title-job_listing %s">Amenities</h2>

    <li>Air conditioning</li><br>
    <li>Free parking</li><br>
    <li>Access to bathrooms</li><br>
    <li>Loading dock</li><br>
    <li>Elevator</li><br>

</aside>

Anyway that's possbile with jQuery?

Halnex

First, you need to wrap each item within a div and give it a class, like so

<aside id="jmfe_widget-2" class="widget widget-job_listing widget_jmfe_widget">

    <h2 class="widget-title widget-title-job_listing %s">Amenities</h2>

    <div class="item">Air conditioning</div>
    <div class="item">Free parking</div>
    <div class="item">Access to bathrooms</div>
    <div class="item">Loading dock</div>

</aside>

Then, do this in jQuery

$('.item').each(function(){
   $(this).wrap('<li></li>');       
});

DEMO https://jsfiddle.net/tu5u0an3/2/

If you can't add any HTML, then try this

$( "#jmfe_widget-2" )
  .contents()
    .filter(function() {
      return this.nodeType === 3;
    })
  .wrap( "<li></li>" )
  .end()
.filter( "br" )
.remove();

This will look inside your aside element, get the contents, remove <br> tags and replace them with <li></li>

DEMO https://jsfiddle.net/tu5u0an3/5/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Wrap each line with li

From Dev

Wrap each line with li

From Dev

how can i wrap each of li element with p tag

From Dev

How to wrap part of text with a <span> or any other HTML tag without new HTML structure being escaped?

From Dev

How to wrap LI tag text for mobile version without js/jquery

From Dev

How do i wrap a <li></li> around each anchor tag dynamically?

From Dev

How to loop text file each line and append other text wrap each line

From Dev

How to loop text file each line and append other text wrap each line

From Dev

How to wrap a html tag around a text selected in an input?

From Dev

How to wrap text into SPAN Tag?

From Dev

Wrap part of text into new element tag

From Dev

Wrap each item in array with HTML tag

From Dev

How to wrap text not part of a tag in a tag?

From Dev

Wrap each line text to an element using JQuery

From Dev

Wrap an HTML form with a specific ID in a new tag

From Dev

How to change the text of a li tag?

From Dev

link wrap with li tag

From Dev

Swift Text Field wrap to new line

From Dev

Wrap text to new line inside table cells

From Java

How to disable prettier settings creating new line of > of html tag?

From Dev

How to save each line in a text file as new file

From Java

How do I wrap text in a pre tag?

From Dev

How to wrap text for a data field tag in Docusign

From Dev

How to wrap each line in quotes in SublimeText?

From Dev

Wrap line of <input> tag

From Java

How to wrap title on to new line react native

From Dev

HTML/CSS - How to make text-overflow in line with each other?

From Dev

unwrap and wrap a li element with a tag

From Dev

Wrap each letter of a string in a tag, avoiding HTML tags

Related Related

HotTag

Archive