How do you call a prompt on page load with jquery? [closed] - javascript

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 2 years ago.
Improve this question
I cant seem to figure it out. This is what I have so far:
<head>
<script src="jquery-3.5.1.min.js"></script>
var gamerName
<script>
$(document).ready(function(){
gamerName = prompt("Please enter your name."," ");
});
</script>
</head>

Keep the var assignment inside the script tag! Otherwise it will be parsed as HTML.
Minimal example;
let gamerName;
$(document).ready(function(){
gamerName = prompt("Please enter your name."," ");
console.log(gamerName);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Related

jQuery: how to add eventListener to whole document/Webpage [closed]

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 2 years ago.
Improve this question
How do I add an eventListener to whole document with jQuery?
$("document").click(function (){
$("h1").css('color', 'red');
})
I want the h1 to change color if clicked anywhere in the document/webpage. Thanks!
Just remove the double quotations in the $("document") line
$(document).click(function (){
$("h1").css('color', 'red');
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h1>Hello</h1>
just using "body" in quotation marks as following also works.
$("body").click(function (){
$("h1").css('color', 'red');
})

JavaScript Expanding Divs not working Correctly for me [closed]

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 2 years ago.
Improve this question
https://jsfiddle.net/alachgar/upezxLas/3/
Hello All,
My Javascript that was working fine earlier now is Broken.. it worked for me just yesterday.. now it is the HOUSING Section Part works fine...
However Starting the Second Section in Light Blue it's Broken... I am not sure what I am missing..!
Please help. Thanks a alot.
Ed-
<script>
function showRent (rent_box)
{
var rent_chboxs =
document.querySelectorAll('[name="rent_eval1"],
[name="rent_eval2"],
[name="rent_eval3"],[name="rent_eval4"],[name="rent_eval5"],
[name="own_concerns"],
[name="address_different"]');
var vis = "none";
for(var i=0;i<rent_chboxs.length;i++) {
if(rent_chboxs[i].checked){
vis = "block";
break;
}
}
document.getElementById(rent_box).style.display = vis;
}
</script>
You just need to change the onclick Event name from showOwn to showRent in from line 78 to line 90 in your HTMl file
'showOwn' is not defined.
Or change it to showRent may work.

How to get the input date element value in jquery [closed]

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 3 years ago.
Improve this question
I have an input box of type = date, I want to capture the date value on change event.
Here is the code snippet
function maintest() {
input = $('<input>').attr({"type":"date"}).change(function() {
alert(this.val());
});
$("#mainDiv").append(input);
}
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body onload ="maintest()">
<div id="mainDiv"></div>
</body>
</html>
.val() is jQuery's method. Wrap it like this to get element's value:
$(this).val();
Change your function to this
function maintest() {
input = $('<input>').attr({"type":"date"}).change(function(e) {
alert(e.currentTarget.value);
});
$("#mainDiv").append(input);
}

Javascript To do list - whats wrong in my code? [closed]

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 6 years ago.
Improve this question
I have been watching a tutorial about how to make a to do list and so far my code is IDENTICAL to the one in the tutorial but still doesn't work-Ive been starring at the code for forever but can't figure out why..
my html (I don't have to include etc because I was writing my code on codepen(javascript,html and css are already being combined):
<body>
<h1>To Do List</h1>
<p><button id="add">Add</button></p>
<ul id="todoList"></ul>
</body>
Javascript:
function addNewItem(){
var listItem = document.createElement ("li");
listItem.innerText = "hello";
var list = ducument.getElementById("todoList");
list.appendChild(listItem);
}
var btnNew = document.getElementById("add");
btnNew.onclick = addNewItem;
In the tutorial the same code works and when you click the add button "hello" is being displayed and in my code nothing happens when i click on the add button..
You have a typo on this line:
var list = ducument.getElementById("todoList");
It's document, not ducument.
See this working fiddle: https://jsfiddle.net/omgtoblerone/h2sL1vu8/
In most browsers, if you hit F12, you'll see an error console. If you had looked at the console, you would've seen the following error:
Uncaught ReferenceError: ducument is not defined
Easy fix!

find nearest td inside element [closed]

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 8 years ago.
Improve this question
Here's my code,
<script>
$(document).ready(function(){
$(".mail").on("click",function(){
alert($(this).closest('tr').find('.td_class div').attr('var'));
});
});
</script>
<table><tr>
<td class='td_class'><div var='value'></div></td>
<td><div class='mail'>click</div></td>
</tr>
<tr><td> </td></tr></table>
okay, I wanna alert 'value' that is div's attribute var...
but it's not working help me...
thank you.
in this particular case
var x = $(this).parent().prev().find('>div').attr('var');
alert(x);
You missed quotes for find(.td_class div)
<script>
$(document).ready(function(){
$(".mail").on("click",function(){
alert($(this).closest('tr').find('.td_class div').attr('var'));
});
});
</script>

Categories

Resources