0

I have been trying to pull all the links out of a certain div into an array and use them elsewhere on the page. It's for the software MyBB:

<div class="pm_alert" id="pm_notice">
    <div class="float_right"><a href="private.php?action=dismiss_notice&amp;my_post_key=d668d58abafb0f4ec8ab4c902e4eb460" title="Dismiss this notice" onclick="return MyBB.dismissPMNotice()"><img src="images/aesthetic/dismiss_notice.gif" alt="Dismiss this notice" title="[x]" /></a></div>
    <div><strong>You have one unread private message</strong> from <a href="http://localhost/mybb/member.php?action=profile&amp;uid=2">test account</a> titled <a href="private.php?action=read&amp;pmid=13" style="font-weight: bold;">take this</a></div>
</div>

The links are generated through the system though, same as the names. So I'd like to pull all 3 of them out of there so I can customize the message without having to edit .lang files. This is the code I'm using now but it isn't working, alert is giving me undefined:

var link_split = [];
var link_split = $('.pm_link > a').map(function(){
    return this;
}).toArray();
alert(link_split['']);
2
  • What kind of array do you need to get? Array of DOM elements, array of jQuery objects, or array of inner text? Commented Jun 8, 2012 at 12:31
  • I need the whole element. I just realized my code doesn't return the whole thing like I wanted (<a href="">stuff</a> instead of just the href). Any ideas? :x Commented Jun 8, 2012 at 12:34

1 Answer 1

1

Maybe the error is in thomething like

.pm_link > a

It should be

.pm_alert a

Try the

alert($('.pm_link > a').length)
Sign up to request clarification or add additional context in comments.

2 Comments

Yep, just a typo on my part, thanks for the help. This is the code that ended up working: var link_split = $('.pm_alert a').map(function(){ return this; }).toArray(); alert(link_split['0']);
Why not to use var link_split = $('.pm_alert a').get();?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.