Solved

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

Posted on 2013-05-23
3
366 Views
Last Modified: 2013-05-23
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
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39191814
$.find("body").attr("class");

Open in new window

0
 
LVL 16

Author Comment

by:hankknight
ID: 39191945
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
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39191974
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
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…

707 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