Decided him, if someone needs him, hevar feed = feeds.entries[i].content; var parsedFeed = feed.replace(/src=/gi, "tempsrc="); var tmpHolder = document.createElement('div'); tmpHolder.innerHTML=parsedFeed;
Decided him, if someone needs him, he
var feed = feeds.entries[i].content; var parsedFeed = feed.replace(/src=/gi, "tempsrc="); var tmpHolder = document.createElement('div'); tmpHolder.innerHTML=parsedFeed;
I have a line containing html markup that includes <img src='path.jpg'/>
<img src='path.jpg'/>
I would like to run a regex for a string to replace each src attr with tmpSrc
So
will turn into
<img tmpSrc='path.jpg'/>
this is in javascript by the way
and here is the root problem, posted elsewhere but not resolved
Browser parses HTML for jQuery without loading resources
How to parse an AJAX response without loading resources?
thank
, , HTML, -, . <img src= <img tmpSrc=, :
<img src=
<img tmpSrc=
var str = "<img src='path.jpg'/>"; // whatever your source string is str = str.replace(/<img src=/gi, "<img tempSrc=");
, , , HTML, -, HTML, . , , , , .
HTML RegExps .
jQuery :
$('img').each(function() { var src = this.src; $(this).attr('tmpSrc', src).removeAttr(src); });
function replace() { var images = document.getElementsByTagName('img'), srcValue, max i; for (i = 0, max = images.length; i < max; i++) { srcValue = images[i].getAttribute('src'); images[i].setAttribute('tmpSrc', srcValue); images[i].removeAttribute('src'); } }
like string:
input = " <img src='path.jpg'/>"; output = input.replace("src","tmpSrc");
using the DOM:
e = document.getElementById("theimg"); e.tmpSrc = e.src; e.removeAttribute("src");
A message opens explaining the problems with using regular expressions to parse HTML . This is complicated and probably not worth the effort. I don’t think there is any way that is guaranteed to work.