简体   繁体   中英

Loading Javascript into Div with Jquery

I am trying to place a constantly updating Donation Ticker on my website that is currently located at http://www.ronpaul2012.com in the . I have tried several solutions around stackoverflow including iframes, but my search abilities are either lacking or there is some java their site is running that I don't know how to work with (or I don't know a thing about javascript, but thats neither here nor there). I played around with several variations and tried some document.ready calls, but I am not sure why nothing comes up.

<head>
<meta charset="utf-8" />
<title>Ron Paul Donation Ticker</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>  
<script>
$('#ticker').load('https://secure.ronpaul2012.com/ #tickerContainer');
</script>

<body>

<div id="ticker"></div>

</body>

Thanks in advance!

Your problem is that the javascript is executing before the div is present. Use this to make the code wait to execute until the document is ready:

$(document).ready( function(){
   $('#ticker').load('https://secure.ronpaul2012.com/#tickerContainer');
 });

Also, I removed the space from your URL, which may have been an issue with loading at the right spot.

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