Binita Gyawali
Binita Gyawali

Reputation: 256

Separate HTMl attributes and values from string

I have a list of strings with HTML elements and values.

define div with class abc with id xyz
consider image with alt this with src that with class responsive
........

I am trying to separate the elements along with their attributes and values like this

 div class abc id xyz
 img alt this src that class responsive
 ...........

I am using the following method

 textElement = string.split ("with") 

which will give me array and then again separating that. Is there any better way to do that?

Thank you

Upvotes: 0

Views: 77

Answers (1)

srp
srp

Reputation: 753

If you don't have any intention to store attributes and values separately for any latter use but just want to print them as you have shown in your question then I would suggest to use replace

textElement = string.replace(/with/g, ""); //i.e. global replacement

I hope this will be helpful.

Upvotes: 1

Related Questions