Naman Tujis
Naman Tujis

Reputation: 53

jQuery click not work

I have a simple code which uses JQuery.

When I click the text given (grjvtrjv) I want it to change to another text(sdfds in this case)

But it isn't working. Please help.

<html>
<head>
</head>
<body>
	<p class="fg">grjvtrjv</p>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(".fg").click(function(){
	$(".fg").html("sdfds");
}
</script>
</html>

NOTE: no php used, but file's extension is .php

Upvotes: 0

Views: 51

Answers (2)

ajtrichards
ajtrichards

Reputation: 30530

Your click function hasn't been written correctly. Your missing a ) after the final }. I'd also put it in the document ready function.

<html>
<head>
</head>
<body>
	<p class="fg">grjvtrjv</p>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function (){
        $(".fg").click(function(){
            $(".fg").html("sdfds");
        });
    });
</script>
</html>

Upvotes: 2

stackoverfloweth
stackoverfloweth

Reputation: 6917

try this instead

    <html>
	<body>
		<p class="fg">grjvtrjv</p>
	</body>
	<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
	<script>
		$(document).on("click",".fg",function(){
			$(this).html("sdfds");
		});
	</script>
</html>

Upvotes: 0

Related Questions