Solved

JavaScript/jQuery: Get attribute value from string

Posted on 2013-05-23
1
405 Views
Last Modified: 2013-06-03
Using jQuery or pure JavaScript, from this code, how can I get "Hello World"?

<script type="text/javascript">

var data = '<' + '!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"' + '><' + 'html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"' + '><' + 'head' + '><' + 'title>Title</title' + '><' + 'meta name="description" content="HR Home Description" /' + '><' + 'script type="text/javascript"' + '><' + '/script' + '><' + '/head' + '><' + 'body class="Hello World"><p>Invalid HTML HERE</div' + '><' + '/html>';

// I want the alert to say: "Hello World"
alert(data);

</script>

Open in new window

0
Comment
Question by:hankknight
1 Comment
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39192478
var msg = data.split("body class=")[1].split(">")[0].replace(/["']/g, "");
alert(msg);

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to make google charts responsive 4 46
jQuery Datatables.js Selecting a Row to get ID 5 36
jQuery on click requires double click 6 28
JS library vs Js framework 11 19
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question