Solved

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

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
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)

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now