Split the string based on
tag using jquery

前端 未结 10 838
温柔的废话
温柔的废话 2021-01-17 20:04

How can i split the string containing
tag using jquery. I tried the following code but it get error in console. I am not sure how to split the strin

10条回答
  •  囚心锁ツ
    2021-01-17 20:45

    Lots of duplicate answers here. This one is different. If you can guarantee the spelling of the
    tag, the other answers are fine. But if you have no control over the HTML, the line break tag could come in different formats:











    ...etc.

    major browsers can all handle all of these, but only the first will be handled by the suggested .split("
    ")
    operation. A more robust option is to use a regular expression to match the tag:

    jQuery(document).ready(function($)
    {
        var brExp = //i;
        var lines = ("this is for testing 
    How are you
    ").split(brExp); });

    I've written the expression to be case-insensitive, allow any number of spaces after '

提交回复
热议问题