1

I'm new to jquery and having a weird problem with it. Somehow jquery is not working on my html-file which I've created as the website's frontpage. The same jquery-code is working if I use it on a blank html-file, so there shouldn't be anything wrong with that or the server that I'm trying it on(000webhost.com).

I've been trying to debug this for couple of days now, so any help would be SO appreciated.

Here's my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>MG</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
jQuery.noConflict();
jQuery(document).ready(function($){
    $("button").click(function(){
      $("#logo").hide();
    });
});
</script>
</head>
<body>
<div id="content">
    <div id="header">
        <div id="logo"><button>test</button></div>
        <div id="sitehistory"> History:<br />Samu added [PIC] (30min ago)</div>
    </div>

    <div id="container">
        <div id="wall">
            <div id="navi"><a id="showlatest" title="Latest">Latest</a> | <a id="showmostpopular" title="MostPopular">Most Popular</a> | <a id="showsearchbox" title="Search">Search</a> </div>
            <?php include("latest.php");?>
        </div>
        <div id="profilebar"><?php include("login-form.php"); ?></div>
        </div>
    <div id="footer">
        <a href="index.html" class="lefty">Home</a>|
        <a href="index.html" class="lefty">Profile</a>|
        <a href="index.html" class="lefty">FAQ</a>|
        <a href="index.html" class="lefty">Contact</a>
    </div>
</div>

</body>
</html>

4 Answers 4

6

You need a

<script type="text/javascript">

before

jQuery.noConflict();
jQuery(document).ready(function($){
    $("button").click(function(){
      $("#logo").hide();
    });
});
</script>
Sign up to request clarification or add additional context in comments.

3 Comments

Also make certain you close out the script tag for the jquery: <script type="text/javascript" src="ajax.googleapis.com/ajax/libs/jquery/1.4.2/…> and then start the other script block.
Consider using a web page validator, as they will pick up things like this. For example, running your code through validator.w3.org shows the issue right off the bat.
Thanks for pointing it out, but it doesn't fix it. That was the way I had it before I started debugging it. Oh, and validator, which I ran, didn't point that out for me as a error.
0

You are missing a script tag

<script>

before

jQuery.noConflict();

Comments

0

You are mixing a link to the jquery script and your own. Try replacing

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
jQuery.noConflict();
jQuery(document).ready(function($){
    $("button").click(function(){
      $("#logo").hide();
    });
});
</script>

by (edited after comment)

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" />
<script type="text/javascript" >
jQuery.noConflict();
jQuery(document).ready(function($){
    $("button").click(function(){
      $("#logo").hide();
    });
});
</script>

See sample here ( in this fiddle, jQuery is loaded by the tool )

2 Comments

It's XHTML so 1st script should be closed with a self-closing /> rather than a </script>
As I replied to the first one, that didn't fix it. I've tried both of them, but if that is the correct syntax for xhtml, thanks for pointing it out to me. :)
0

This works fine - http://jsfiddle.net/dhruvasagar/HKR4X/1/

Baburo, actually the answer with the most votes (by @Scott Brown) does answer it. The thing is, that there needs to be a separate tag for loading jquery and a separate one for defining your javascript code.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
    jQuery.noConflict();
    jQuery(document).ready(function($){
        $('button').click(function(){ $('#logo').hide(); });
    });
</script>

1 Comment

That's what I was afraid of. You didn't change anything from my code, right? Seems that error is something beyond the code I wrote.

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.