Extract HTML Elements from Text Area

I have a WYSIWYG editor that will populate a textarea with HTML and some images.  I would like to know how to traverse the HTML (within the textarea), extract the 'src' attribute from the image and pass it to either a Coldfusion variable or as a hidden element within the form.
gKillerAsked:
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.

Albert Van HalenAnalyst developerCommented:
I would get the contents of the editor, put it into an element and get all the elements you want by using getElementsByTagName.
That method will return an array of your choosen elements which you can traverse.

I created a small demo for you at http://jsfiddle.net/yNVv7/
Just put some html into the textarea, click on 'check' and it will alert the src attribute of each img element.
0

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
gKillerAuthor Commented:
Thanks for the demo. Although the demo worked, it did not return the correct image when I used it with the WYSIWYG editor. After doing some debugging, it was discovered that the editor created it's own objects within the HTML which did not yield the correct results when used with your code.  W did eventually find the right instances and that generated the correct results.

Your demo did come in handy in another part of our project, however.  So that it appreciated.

Thanks again.
0
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
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.