Vignesh Pichamani Vignesh Pichamani - 1 month ago 11
Javascript Question

Split the string based on <br/> tag using jquery

How can i split the string containing

<br/>
tag using jquery. I tried the following code but it get error in console. I am not sure how to split the string based on
<br/>
tag Here is the code what i tried

jQuery(document).ready(function($)
{
var lines = jQuery('this is for testing <br/> How are you<br/>').split('<br/>');
jQuery.each(lines, function() {
alert(this);
});
});


Any suggestion would be great.

Answer

You want to split a vanilla string, don't pass it to $() rather simply;

jQuery(document).ready(function($)
    {
        var lines = 'this is for testing <br/> How are you<br/>'.split('<br/>');
        jQuery.each(lines, function() {
            alert(this);
        });
    });