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);
}
Related
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>
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');
})
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 am trying to access the below tag class="topbar"
<div id="swagger-ui">
<section data-reactroot="" class="swagger-ui swagger-container">
<div class="topbar">
<div class="wrapper">
<div class="topbar-wrapper">
I have tried this:
var x=document.getElementById("swagger-ui");
var y=x.getElementByClassName("swagger-ui swagger-container");
var z=y.getElementByClassName("topbar");
Also,
How can I set value in js? I have to set the value for input type text
<div class="wrapper"><label>Value:</label><section class=""><input type="text"></section></div>
You can do something like the following:
var topbar = document.getElementsByClassName('topbar');
or
var topbar = document.querySelector('.topbar');
try to use querySelector
var x=document.querySelector("#swagger-ui");
var c=document.querySelector(".swagger-ui");
var y=document.querySelector(".swagger-container");
You're code is almost perfect, but you need to spell getElementByClassName correctly, and add an indexer for getElementsByClassName. Try adding [0] after each getElementsByClassName function. Like this: getElementsByClassName[0]
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 4 years ago.
Improve this question
Trying to do something once HTML is loaded and document get ready. However, code doesn't seems to work.
HTML:
<div class="dataprocess"></div>
JS:
$(document).ready(function(){
if( $('div').hasClass('dataprocess') ) {
console.log('working');
}
});
Not able to get working on console. What am I doing wrong?
In your snippet, you're missing the closing brackets for the $(document).ready() function.
$(document).ready(function(){
if($('div').hasClass('dataprocess')){
console.log('working');
}
});
This is the only visible issue in your code.
Also some other things you may have forgotten:
Include the JavaScript file
Include the jQuery dependency
I think the best option is to use id to call the element:
<div id="data_id" class="dataprocess"></div>
and then JS
$(document).ready(function(){
if($( "#data_id" ).hasClass( "dataprocess" )){
console.log("working");
}
});
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 9 years ago.
Improve this question
I can't figure out why the jQuery functions will not work with the html here
JS Fiddle: http://jsfiddle.net/JonaTheApprentice/E89rg/
function addItem() {
$('#list').append('<li><input type="checkbox" /> item</li>');
}
function removeItem() {
$('#list').children().filter(function () {
return this.firstChild.checked;
}).remove();
}
I don't see an element with id="list", that's what #list refers to.
I think you mean #items-listed. Changing that, and it works
I would get the value from the input id. I would also assign a click event for cleaner coding. Here is an example of your fiddle adding an item. Removing an item is just the reversal.
DEMO http://jsfiddle.net/E89rg/5/
$('#Enter').click(function(){
var Val = $('#item').val();
$('#items-listed').append('<li><input type="checkbox" />'+Val+'</li>');
});