why doesn't this jQuery not find a div with a specific name?
Why won't this jquery work? It's supposed to take the content out of a div named poop and insert it into a div named moreinfo. Instead, there's no content at all in the moreinfo div.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
jQuery(docume开发者_如何学Pythonnt).ready(function(){
var info = jQuery('poop').text();
jQuery('moreinfo').text(info);
});
</script>
'Poop', really?
Well, your code is looking for a <poop>
tag, not a <div id="poop">
. To select by ID, use jQuery('#poop')
.
You might mean:
var info = jQuery('#poop').text();
jQuery('#moreinfo').text(info);
The #
means the elements ID, a .
would mean it's class name
If you're trying to select by ID, use:
jQuery('#poop')
If you're trying to select by class name, use:
jQuery('.poop')
Basically, use a regular CSS selector...
if the poop and moreinfo are supposed to be class names, then you’ll need to have a dot in before the name.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js">
jQuery(document).ready(function(){
var info = jQuery('.poop').text();
jQuery('.moreinfo').text(info);
});
</script>
You need to use #
to access IDs, like jQuery('#moreinfo')
精彩评论