Ok this is as basic a jquery coding as you can get.. Why does div id=tx show on load??? I'm testing this on wamp localhost...www folder. Any help?? Is there anything i need to do to save the jquery.js? jquery.js is in the same folder as this page.

<html>
<head>
	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript">
	$(document).ready(function() {
		$('#tx')hide();
	});
	</script>
</head>
<body>

<div id="tx">
fjdskla
</div>



</body>
</html>

Recommended Answers

All 2 Replies

1) Move your script from the <head> to the bottom of the <body>. Then you won't need '$(...).ready'. See Souders book High Performance Web Sites if you need more reasons.

2) Don't use jQuery if you don't have to. Hiding/showing a div is simply a matter of switching it's 'display' style between 'block' and 'none'. Write yourself a little function if you'll do this often:

var tx_div = document.getElementById( 'tx' );
hide( tx_div );

function hide( div ) { div.style.display = 'none'; }

3) If you want the div hidden initially, use a stylesheet or an inline style:

<div id="tx" style="display: none">
Member Avatar for stbuchok

You are missing a dot.

$('#tx').hide();
        ^

Hopefully the arrow lined up properly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.