0

I am using podPress on my Wordpress instance to give users some playback controls in listening to our podcast episodes. Below, I have the code found on the play button of these controls.

What I'd like to do is write some jQuery that can scrape out the URL of the podcast episode. In this test case, that URL is http://www.test.com/episodes/2012_04_11_episode.mp3. I'd like to write this URL to a variable and then use it elsewhere on my site where I'm building an HTML5 audio player that features our latest episode in a more central location.

Based on the way podPress writes these players, the ID of the link with the URL that I'll need will ALWAYS be "podpress_html5_play_1". I know how to target this ID, but I don't know how to grab a string that is nested within the "onclick" element. Can anyone help?

Here is the code found on the link:

<a id="podpress_html5_play_1" href="javascript:void(null);" onclick="podPressenprintHTML5audio('1', 'http://www.test.com/episodes/2012_04_11_episode.mp3', true);" class="podpress_play_button" title="Play &gt;" style="background-image:url(http://www.test.com/beta/wp-content/plugins/podpress/images/play_button_dyn_v4_32.png);"></a>
1

3 Answers 3

1
var link = 'http'+$('#podpress_html5_play_1').attr('onclick').split('http')[1].split("'")[0];

FIDDLE

Sign up to request clarification or add additional context in comments.

Comments

0

try this:

var link = $("#podpress_html5_play_1").attr("onclick");

Comments

0

Just Do this: Assuming you are using jQuery;

 // Get the onclick attribute

    var onclickAttr = $('a#podpress_html5_play_1').attr('onclick');

// strip and split it into an array with the single quote string

    var a  = onclickAttr.split("'");

// Now a[3] holds your link

alert (a[3]);

JSFiddle: http://jsfiddle.net/P6Kzt/

Comments

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.