Using jQuery to pull out element strings

I have lines like below scattered throughout my markup:
<img id="dance_1"  class="video" src="media/dancing1.jpg" onclick="playVideo(irishJig1.flv') />

I want to use jQuery to build an array of the strings passed to the playVideo()  function so I can then preload  all of these videos, one at a time. The JavaScript will be something like

var vids =$(';

where the ??? is something that will look inside the line and pull out the name of the video that that line will play. It's that "something" that I'm not sure of.  It would be easy if I were pulling the value of an attritute in the line, but I'm just looking for a string buried in the line.  

What is the best way to do this with jQuery?

Thanks for any ideas.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

var arr=[];
		var result = $(this).attr('onclick').match(/([^\)]+)\)$/);

Open in new window

stevaAuthor Commented:
Ok.  Thanks. A couple of questions to make sure I understand.

 We're feeding the onclick attribute in  the line to a JavaScript match() function.  (I didn't realize you could drop a JavaScript method  into jQuery code, so I learned something there.)  

So in my example the string we feed to match() would be


(I left the leading single quote off the original statement of the line.)

 From this we want the string  'irishJig1.flv'.

Your regular expression says

            "Take any characters that are not ')', one or more times, all followed by a ')' that ends the line."

The match() method returns the parenthesized portion of the regular expression in element 1, which would just be the 'irishJig1.flv' string and this is put at the end of our global arr array. (So this is like a "push" onto the array?

Did I miss anything?

Thanks for your help.
>> We're feeding the onclick attribute in  the line to a JavaScript match() function
Sorry about that. You need to first convert it to an actual string. match is a method of the String object. So it should have been:

String( $(this).attr('onclick') ).match

As for your explanation of the regex, yes, you got it. However, I assume you don't want the quotations sorrounding the filename. In which case you should use the modified version below.

>>So this is like a "push" onto the array?

>>Did I miss anything?
No, you got good grasp of what was previously posted.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

	<script src=""></script>
	<script type="text/javascript">
var arr=[];
                var result = String( $(this).attr('onclick') ).match(/\(['"]?([^'"]+)['"]?\)/);
	<img id="dance_1"  class="video" src="media/dancing1.jpg" onclick="playVideo('irishJig1.flv')"/> 
	<img id="dance_1"  class="video" src="media/dancing1.jpg" onclick="playVideo('irishJig3.flv')"/> 
	<img id="dance_1"  class="video" src="media/dancing1.jpg" onclick="playVideo('irishJig5.flv')"/> 

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

stevaAuthor Commented:
Thanks for your help.  I appreciate it!
stevaAuthor Commented:
Hello Hielo,

When you solved my problem a few days ago you did something interesting but which I don't understand,  and which is illustrated in the attached image.   You used ['"] in the regular expression to find the beginning of the file name, that is, single OR double quote mark, though it's clear from the markup that  the videos are always in single quotes.  Why did you include the double quote?

stevaAuthor Commented:
Sorry.  Somehow the wrong image go uploaded above .  It should be  this:

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.