开发者

Extracting content from <![CDATA []]>

开发者 https://www.devze.com 2023-01-31 00:55 出处:网络
I am having a string like: \"<![CDATA [Lorem ipsum dolor sit amet, <a href=\"http://www.google.com\">consectetur&l开发者_如何学Ct;/a> siptum. adipiscing elit. Phasellus pulvinar hendrerit

I am having a string like:

"<![CDATA [Lorem ipsum dolor sit amet, <a href="http://www.google.com">consectetur&l开发者_如何学Ct;/a> siptum. adipiscing elit. Phasellus pulvinar hendrerit malesuada. Mauris eget ante nulla. Suspendisse tempus lorem id.]]>"

using jquery I need to extract the entire content which is inside the <![CDATA []]>. consider the entire data to be stored in a string variable. Please help me with this.


You can do this with pure javascript, using substring:

var cDataString = "<![CDATA [Lorem ipsum dolor sit amet, <a href=\"http://www.google.com\">consectetur</a> siptum. adipiscing elit. Phasellus pulvinar hendrerit malesuada. Mauris eget ante nulla. Suspendisse tempus lorem id.]]>";
cDataString = cDataString.substring(0, (cDataString.length - 3)); // remove ]]>
cDataString = cDataString.substring(10, (cDataString.length)); // remove <![CDATA [
alert(cDataString);
0

精彩评论

暂无评论...
验证码 换一张
取 消