1

Can we use jQuery to get an attribute value by load function?

$(#id).load('url of page #source id').attr();
2
  • 3
    Nope - Why do you want the attribute, might be feasible to use a storage method like cookies / local storage Commented Dec 16, 2019 at 1:44
  • 1
    Maybe you can take a look for ajax, load back content by url Commented Dec 16, 2019 at 2:12

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.