Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I just finished the introductory course on Codecademy and I wanted to use it on a web project but I can't seem to get it working.
test.html
<html>
<head>
<title>jQuery</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="test.js"></script>
</head>
<body>
<p style="font-family: verdana;">wfef</p>
</body>
</html>
test.js
$(document).ready(function() {
$('p').click(function() {
$(this).hide();
};
});
You have a syntax error in your code. You've omitted a closing parenthesis. Try this:
$(document).ready(function() {
$('p').click(function() {
$(this).hide();
}); // added a ) here.
});
Use this :
$(document).ready(function() {
$('p').click(function() {
$(this).hide();
}); // Missed ')' to close click function
});
Once you correct your actual javascript as suggested in other posts, make sure that the browser can actually find your file, test.js. In chrome you can hit ctrl + shift + j and look at the console for errors and make sure that your file can actually be found. It should be in the same directory as your other html file.
$(document).ready(function() {
$('p').click(function() {
$(this).hide();
}); //Syntax error here! Required a ) brace to close your .click(function () {
});
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
trying to load html page to div using jQuery ajax im pretty sure it's right but i don't know why exactly it's not working.
that's my code:
<div class="second">
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("button").on("click",function(){
$('#second').load($(this).data("page"));
});
});
</script>
Consider the following code.
$(function() {
$("button").click(function() {
$(".second").load($(this).data("page"));
});
});
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<button data-page="page-2.html">Get Page 2</button>
<div class="second"></div>
This will work properly as it uses a Class selector to target he proper <div> element.
Change:
$('#second')
To:
$('.second')
As second is a class, not an id.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
here below is my code i can't seem to find what is wrong it is not redirecting to the link.
<html>
<head>
<script type="text/javascript" src="<?= baseurl(); ?>/public/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(function() { $("formRedirect").submit(); });
});
</script>
</head>
<body>
<form id='formRedirect' action="http://www.example.com/something/something.aspx" method="post"><input type="submit" name="redirect" value='<?= $token ?>'</form>
</body>
Try this:
<html>
<head>
<script type="text/javascript" src="<?= baseurl(); ?>/public/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#formRedirect").submit();
});
</script>
</head>
<body>
<form id='formRedirect' action="http://www.example.com/something/something.aspx" method="post"><input type="submit" name="redirect" value='<?= $token ?>'</form>
</body>
For id jquery detect them with #
Try like this
$("#formRedirect")[0].submit();
Use
$(document).ready(function() {});
or
$(function(){})
Both same
U have added $(function(){}); inside document.ready
$(function(){}); is similar to $(document).ready(function() {});
Use following code:
$(document).ready(function() {
$("#formRedirect").submit();
});
I find the Chrome console to be very helpful in debugging situations like this. I would start by making sure you are getting a result from your jQuery selector.
You can open the Chrome console by pressing F12
In the Chrome console, type $("formRedirect") and see if you get any results. You probably won't, since you are missing the # ID selector.
Next, try submitting your corrected jQuery object. If it doesn't work, try accessing the actual HTML object by adding in a [0] at the end of your selector, as suggested by #Anik.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
i have this jquery code and html it is working on jsfiddle.com(http://jsfiddle.net/9rJev/) and this is the working example but when i get it to notepad++ its not working, and this is my code on notepad++
<html>
<head>
<script type="text/javascript" src="js/jquery.1.3.2.min.js" ></script>
<script type="text/javascript" src="js/jquery.1.6.4.min.js" ></script>
<script type="text/javascript" src="js/jquery-ui.min.js" ></script>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$('#movedown').ready(function(){
`$('#test').slideUp();`
})
$('#movedown').mouseover(function() {
$('#test').slideDown();
});
$('#movedown').mouseleave(function(){
$('#test').slideUp();
});
</script>
</head>
<body>
<div id="movedown">
<h4>yazan</h4>
<div id="test" style="background-color:lightgrey; border:2px solid grey;padding:10px;">Hello, this will slide down.</div>
</div>
</body>
</html>
but its not working on google chrome anyone have any idea what is the issu.
please help.and thanks
Change your JS to this:
$(document).ready(function(){
$('#movedown').ready(function(){
$('#test').slideUp();
})
$('#movedown').mouseover(function() {
$('#test').slideDown();
});
$('#movedown').mouseleave(function(){
$('#test').slideUp();
});
});
And also remove all but 1 jquery reference. Note you need to include the ready function, and you had some odd characters around $('#test').slideUp(); which caused JS errors. After these minor changes your code performed fine for me.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I am trying to use this code in my html file. It will work if I use the link http://jsfiddle.net/eqkmv/1/show/ however the javascript doesn't work when I try to View Page Source and copy/paste the code into an html file.
here is the javascript:
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
$('#search').submit(function (e) {
e.preventDefault();
MoneyForTrip();
return false;
});
function MoneyForTrip() {
var money = parseInt(document.getElementById('moneyfortrip').value);
$('.trip-result').hide();
if (money <= 800) {
$('.trip-less-800').show();
}
if (money > 800 && money <= 1200) {
$('.trip-800-1200').show();
}
}
});//]]>
</script>
Am I missing something?
Add jQuery in the <head>
<script src= "http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have these number of <a href />links in a HTML page:
<a ...>
<a ...>
.....
<a ...>
What I want is on the click of each link I have to show a text file on same html page.
a text file can be shown in a textarea or iframe.
How can I accomplish that?
.........EDIT..............
correct code
<html>
<head>
<title>Ajax Test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
$("a").click(function(e){
e.preventDefault();
$.get( $(this).attr("href") ).done(function(e){
$("textarea").html(e);
});
});
});
</script>
</head>
<body>
foo bar<br>
<textarea></textarea>
</body>
</html>
You can use AJAX to get the text file data from the server, then put it into the text field.
Demo: http://jsfiddle.net/DerekL/63BLB/
$("a").click(function(e){ //select all <a>
e.preventDefault(); //remove default link effect
$.get( $(this).attr("href") ) /*AJAX (using jQuery)..
..and insert the URL of text file*/
.done(function(e){ //When it is downloaded,
$("textarea").html(e); //shows it in <textarea>
});
});
If you are new to jQuery, you may want to check out their documentation, especially $.ajax. :)
Note: You can only fetch text files in the same origin.
Note 2: The code above is written using jQuery. If you do not want to use jQuery, you will have to do the whole native new XMLHttpRequest thing.