AJAX body class html
source link: https://www.codesd.com/item/ajax-body-class-html.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
AJAX body class html
I have this AJAX function
type: "GET",
url: url,
cache: false,
dataType: 'html',
success: function(data){
},
error: function(){ },
complete: function(){ }
});
ofcourse that "data" represent entire document with <html>
but I only want to get class of body element from this data variable.
Does anyone know how to do that? To get class of body element from retrieved data?
Thank you very much for every advice.
You can do this in plain JavaScript:
success: function(data){
var parser = new DOMParser();
doc = parser.parseFromString(data, "text/html");
// Your class(es)
var docClass = doc.body.getAttribute('class');
// Garbage collection, you don't need this anymore.
parser = doc = null;
}
Related Articles
Extract all classes from the body element of the AJAX-ed page and replace the body classes on the current page
How to overlay a new div on the entire body of HTML using Jquery?
Define the body class with the jquery cookie plugin
How to display ajax response to HTML in Code Lighter
jQuery works to change body class in an index
Add the body class to the node in Drupal 8
Drupal 8 - adding body class based on a taxonomy term or other
Using Jade, how can I declare a body class in an extended model?
Change the value of the placeholder according to the body class
How to call ajax in my HTML form
Add Woocommerce product type to body class class
Css: in the body class, the simple text becomes dark but do the links also get it?
Unable to set body class with Template.helpers
Can we use it like this & lt; Body class = & ldquo; All & rdquo; & Lt;! - [if IE 7] & gt; Class = & ldquo; Ie & rdquo; & Lt; [Endif] - & gt; & Gt;
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK