Reputation: 11
Can we use jQuery to get an attribute value by load function?
$(#id).load('url of page #source id').attr();
Upvotes: 1
Views: 503
Reputation: 151
I quite really didn't understood what you are looking for, Hope this helps, :D
You want to add ul inside your div new-projects
, and you need to get attribute of ul
element. You can do as follows
Suppose HTML is like this
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>load demo</title>
<style>
body {
font-size: 12px;
font-family: Arial;
}
</style>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
</head>
<body>
<b>Projects:</b>
<div id="new-projects"></div>
<script>
$( "#new-projects" ).load("/load.html #projects ul", function(data){
var x = data;
$(x).find('ul').attr('style'); //console.log or alert this
} );
</script>
</body>
</html>
load.html
<html>
<body>
<div id="projects">
<ul style="color:blue">
<li>Test</li>
<li> This</li>
</ul>
</div>
</body>
</html>
Upvotes: 2