How to strip HTML tags from div content using Javascript/jQuery?

前端 未结 6 883
梦毁少年i
梦毁少年i 2020-12-31 22:24

I had made one div tag and stored its contents in a variable. If this tag contains p,b or any other tags then it should be removed from string. How

6条回答
  •  孤城傲影
    2020-12-31 23:07

    Solution Using JQuery:

    var content = "

    Dear Andy,

    This is a test message.

    "; var text = $(content).text();

    Solution using JavaScript:

    function removeTags(){
        var txt = document.getElementById('myString').value;
        var rex = /(<([^>]+)>)/ig;
        alert(txt.replace(rex , ""));
    
    }
    

    Also look a this link: Strip HTML Tags in JavaScript

提交回复
热议问题