0

I have the following script that grabs all the contents from my Intranet Home Page and displays it on a page.

I was wondering, is it possible to just get the value inside this element <div id="username">my.username</div> that is on my home page?

Current Code:

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<script type="text/javascript">
$.get('http://intranet', function(data){ 
    $(data).appendTo(document.body); 
    //$('#username').attr('id')
});
</script>
7
  • Is the #username tag inside the data? Commented Sep 13, 2016 at 9:53
  • Try with URL 'http://intranet #username' Commented Sep 13, 2016 at 9:53
  • why not go for iframe and src Commented Sep 13, 2016 at 9:54
  • @KARASZIIstván Inside the home page HTML is <div id="username">my.username</div> Commented Sep 13, 2016 at 9:56
  • 1
    just refer this developer.mozilla.org/en/docs/Web/HTML/Element/iframe Commented Sep 13, 2016 at 9:58

1 Answer 1

1

If I understand you correctly, then this should work:

$.get('http://intranet', function(data){ 
    var username = $('#username', data).text();
    alert(username);
});
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.