Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

innerHTML to plain text?

  • 23-10-2007 10:11pm
    #1
    Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭


    Trying to do a greasemonkey script and JS is not my area. :/

    I have an innerHTML string that contains HTML tags. I want to remove them all so it is only the text.

    Is there a way to do this?


Comments

  • Registered Users, Registered Users 2 Posts: 378 ✭✭sicruise


    function removeHTMLTags(){
    	if(document.getElementById && document.getElementById("input-code")){
    		var strInputCode = document.getElementById("input-code").innerHTML;
    		/* 
    			This line is optional, it replaces escaped brackets with real ones, 
    			i.e. &lt; is replaced with < and &gt; is replaced with >
    		*/	
    		strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
    			return (p1 == "lt")? "<" : ">";
    		});
    		var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
    		alert("Input code:\n" + strInputCode + "\n\nOutput text:\n" + strTagStrippedText);	
    	}	
    }
    

    I found this here... http://robertnyman.com/roblab/javascript-remove-tags.htm


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    excellent! Cheers.


Advertisement