[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

JavaScript/jQuery: Find class attribute of body from a string

How can I get the class attribute of the body tag from a string?

This does NOT work:
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>

<script type="text/javascript">

eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('e r=\'<!h 2 f "-//g//4 j 1.0 B//d" "5://6.3.8/i/9/4/9-k.l"><2 m="5://6.3.8/n/o" q:c="s"><a><b>t</b><u v="w" x="y z A" /><7 C="D/E"></7> </a><F G="H I"><p>J K L</M></2>\';',49,49,'||html|w3|DTD|http|www|script|org|xhtml1|head|title|lang|EN|var|PUBLIC|W3C|DOCTYPE|TR|XHTML|transitional|dtd|xmlns|1999|xhtml||xml|data|en|Title|meta|name|description|content|HR|Home|Description|Transitional|type|text|javascript|body|class|hello|world|Invalid|HTML|HERE|div'.split('|'),0,{}))

alert(data);
alert( $(data).find('body').attr('class') );

</script>

</head>
<body>
</body>
</html>

Open in new window

0
hankknight
Asked:
hankknight
  • 2
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
$.find("body").attr("class");

Open in new window

0
 
hankknightAuthor Commented:
sedgwick, your code is useless to me.  I need to get this from a STRING not from the DOM.  Please test it with the code I posted.  Thanks.
0
 
Meir RivkinFull stack Software EngineerCommented:
u got nothing in the body, no class attribute no nothing.
what is data?
is this the html where u try to run the code from?
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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now