Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

JavaScript/jQuery: Get attribute value from string

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

ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial