Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8276437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:22:32+00:00 2026-06-08T08:22:32+00:00

I have some JavaScript that should be getting this image URL[1] from an XML

  • 0

I have some JavaScript that should be getting this image URL[1] from an XML document with the following code. However Chrome’s console returns Uncaught TypeError: Cannot read property '1' of null on this line. Is the regex incorrect?

var image = $(post.description.match(/<br\/>(<a.*><img.*<\/a>)<br\/>/)[1]).addClass('photo');

[1] http://photos-c.ak.fbcdn.net/hphotos-ak-ash4/391316_483838581645230_1080523933_s.jpg

The XML is structured like so:

<description>
<![CDATA[
Extendemos una cordial felicitación a Reserva de la Biosfera Banco Chinchorro que celebra su aniversario el día de hoy.
Un especial saludo a Maricarmen García, Directora de la Reserva y Líder 2010 del Programa de Liderazgo. ¡Estamos muy
orgullosos de su trabajo!<br /> <br /> We would like to co
]]>
<![CDATA[
ngratulate Banco Chinchorro Biosphere Reserve who is celebrating their anniversary today. A special greeting to Maricarmen
García, the Reserve&#039;s Director and 2010 MAR Leadership Fellow. We are so proud of your work!<br /> <br />
<a href="http://pyucatan.conanp.gob.mx/chincho.htm" target="_blank" rel="nofollow nofollow"
onmousedown="UntrustedLink.bootstrap($(this), &quot;HAQE2sh3f&quot;, event, bagof({}));">http://pyucatan.conanp.gob.mx/chincho.htm</a><br/><br/>
<a href="http://www.facebook.com/photo.php?fbid=483838581645230&amp;set=a.167790786583346.41662.123942950968130&amp;type=1&amp;relevant_count=1"
title="" target=""><img class="img" src="http://photos-c.ak.fbcdn.net/hphotos-ak-ash4/391316_483838581645230_1080523933_s.jpg" alt="" /></a>
]]>
</description>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:22:34+00:00Added an answer on June 8, 2026 at 8:22 am

    Is the regex incorrect?

    Yes. /<br\/>(<a.*><img.*<\/a>)<br\/>/ tries to match br-tags without a space, and also in the string you gave us there is no <br> after the link. So, the match returns null and has no property “1“.

    Anyway, Regex is not suited for this task. Just get the textContent of your <description> node, parse it as HTML with jQuery (see Can jQuery Parse HTML Stored in a Variable?), or even as X[HT]ML with jQuery.parseXML, and use a selector to get the a > img element out of it, in order to read the src attribute.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some JavaScript code that works in IE containing the following: myElement.innerText =
I have some javascript code that saves a cookie. However, if after saving the
Here is the situation. I have some javascript that looks like this: function onSubmit()
I have some Javascript code that will programmatically register an COM interop assembly by
I have some javascript code that creates an img tag with a mouseover callback,
I have some Javascript code that creates 2 arrays: One for Product Category and
I have some third-party Javascript that has statements like this: FOO = function() {
I have some javascript that I am using for some audio on my website:
I have some javascript that goes out and fetches a javascript class on another
I have some JavaScript that I'm trying to benchmark the time it takes to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.