Use jquery to split a string to new line break at certain character

374
November 21, 2016, at 5:02 PM

Currently, the string is

Package A (123 queries) Package B (212 queries)

Is it possible to use jquery to split it into new line like

  • Package A (123 queries)
  • Package B (212 queries)

I was thinking to insert line break after each closing bracket. But not sure if it is appropriate.

-- EDIT --

In HTML

<ul class="list">
    <li><span id="requested-package">@Model[0].regDescription[a]</span></li>
    <li>Testing</li>
</ul>

Output - I want to make the Plan A in next line

Answer 1

Use .replace but try to be as specific as possible. Here we look for where you have a closing bracket followed by a space followed by 'Package' followed by another space ') Package '. This should help prevent erroneous results

'Package A (123 queries) Package B (212 queries)'.replace(') Package ', ')\nPackage')
Answer 2
'Package A (123 queries) Package B (212 queries)'.replace(') ', ')\n')
Answer 3

Add any special character where you want to split the string and replace it with a line break, this should add a new line in html.

For example

var string = "Package A (123 queries)~Package B (212 queries)~Package C (212 queries)";
string = string .replace(/~/g, "<br />");
Rent Charter Buses Company
READ ALSO
paginationjs after client side refreshes , change the page no

paginationjs after client side refreshes , change the page no

I am using pagination plugin from this website http://paginationjs. com/.

290
Creating Tabs with a function

Creating Tabs with a function

I am trying to create a function that will create tabs dynamically. Below is how the function will work:.

321
how to make jquery.tabs takes &lt;li&gt; name instead of &lt;a&gt; href

how to make jquery.tabs takes <li> name instead of <a> href

here is an example of what i need to achieve when i click on a <li> i want to change the tabs instead of clicking on <a> i need it for a reasons is there is a way to achieve that.

350
Bootstrap equal column heights using row-eq-height dont work with my page

Bootstrap equal column heights using row-eq-height dont work with my page

I am working on a page and want the left orange div to always be at the same height as the right div. [nnn]The left div is the orange one, this is the navigation with links.

426