0

Hi I am using the following code :

breakContent = breakContent.replace(/<div>/g, ' <div>');

Here breakContent is a string that contains html code. I need to provide space before div tag.The above code works fine for div without any attribute like id, style,etc...

So what I need is the working code including attributes in div tag...

I tried the below code..but it does not give space before div and instead it replace the div with space

 breakContent = breakContent.replace(/<div\s*[\/]?>/gi, " ");

1 Answer 1

2

Just change it to:

breakContent = breakContent.replace(/<div/g, ' <div');

Removing the trailing > will allow for <div> tags with attributes.

EDIT: Of course, this could pick up text that isn't actually a <div> tag, if you have text matching <div that isn't a tag.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.