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
Solved

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

Posted on 2013-05-23
3
364 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
  • 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

808 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