简体   繁体   中英

Get element value from web page using jQuery $.get

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>

If I understand you correctly, then this should work:

$.get('http://intranet', function(data){ 
    var username = $('#username', data).text();
    alert(username);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM