Using these sources:
- parse html inside cdata using jquery or javascript
- jQuery.parseXML
- https://www.w3schools.com/xml/dom_cdatasection.asp
It is essential that you get your content correctly as XML, by setting the dataType
to 'xml'
.
This code is self-contained and works:
var xmlString = '<Customer><![CDATA[ <img src="y1" /> ]]></Customer>';var xmlObj = $.parseXML(xmlString);var cdataText = xmlObj.firstChild.firstChild.textContent;var jqueryObj = $(cdataText);var imgUrl = jqueryObj.find('img').attr('src');console.log(imgUrl);
This is slightly imprecise because you don't give quite enough information to exactly reproduce your situation. I will start as though this from your question is the only part of your code:
if (feed_image_type == "description") { item_img = $($(this).find('description').text()).find("img").attr("src");}
This ought to get close:
if (feed_image_type == "description") { var cdataText = $(this).firstChild.firstChild.textContent; var jqueryObj = $(cdataText); item_img = jqueryObj.find('img').attr('src');}