I have a HTML string which is a mix of text plus HTML tags, which i\'m trying to convert into an object. So for e.g. my HTML string would look like:
Pay using yo
$.parseHTML()
parses a string into an array of DOM nodes.
To create the object you need to add $()
:
$($.parseHTML(yourString))
Take a look at this fiddle: http://jsfiddle.net/j05ucnfv/
Reference: http://api.jquery.com/jQuery.parseHTML/
Use
$.parseHTML()
instead of
$(HTMLSTRING)
See below JS Code..
var HTMLSTRING = 'Pay using your <img src="visa-src" /> or your <img src="mc-src" />';
var HTMLSTRING1 = '<img src="visa-src" /> or your <img src="mc-src" />';
console.log($.parseHTML(HTMLSTRING));
console.log($.parseHTML(HTMLSTRING1));
Demo Fiddle