Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
114
rated 0 times [  119] [ 5]  / answers: 1 / hits: 6023  / 5 Years ago, tue, july 9, 2019, 12:00:00

I am having a function takes a string input. the string input is noting but a group of html tags like below



<section><div><span><bold></bold></span></div></section>


and i want the output to be like below



[<section>,<div>,<span>,<bold>,</bold>,</span>,</div>,</section>]


guys pls help me how to split the html string to an array


More From » jquery

 Answers
7

You can use regex and .match() to do this.



Demo:





var text = <section><div><span><bold></bold></span></div></section>;
console.log(text.match(/<.*?>/g))




[#6988] Friday, July 5, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
moriah

Total Points: 201
Total Questions: 100
Total Answers: 82

Location: Tuvalu
Member since Sun, Sep 4, 2022
2 Years ago
moriah questions
;