Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

separate string with html into two strings

I'm trying to separate a string with html and non-html in it into two strings.

My javascript string is:

<span>1x</span> Front-line zero tolerance productivity

I want this to be separated into two variables

var quantity = "1x";
var name = "Front-line zero tolerance productivity";
like image 862
ThomasReggi Avatar asked Jun 18 '26 22:06

ThomasReggi


1 Answers

Split when a <span> or </span> tag is found.

string = "<span>1x</span> Front-line zero tolerance productivity"

tokens = string.split(/<\/?span>/);  // returns ["", "1x", " Front-line zero tolerance productivity"]
var quantity = tokens[1]  // "1x"
var name = tokens[2];     // "Front-line zero tolerance productivity" 
like image 120
user278064 Avatar answered Jun 21 '26 11:06

user278064



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!