jQuery Attribute Equals Selector is not working. Please, have a look into it.
Thanks in advance. :)
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.4/jquery.mobile-1.4.4.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.4/jquery.mobile-1.4.4.min.js"></script>
<script type="text/javascript" >
$( document ).ready(function() {
alert($( "input[myattr='navo']" ).value);
$( "input[myattr='navo']" ).value="Simon Commission";
alert($( "input[myattr='navo']" ).value);
});
</script>
</head>
<body>
<input type="text" myattr='navo' value="Morley Minto Reform" />
</body>
</html>
Try this,
alert($( "input[myattr='navo']" ).val());
in jQuery value can be get using the method val(), it doesn't have any property like value.
The .value property doesn't exist on a jQuery object. If you want to access the value you have to call the .val() function; if you want to change the value, you have to pass the new value into the .val("some value") function.
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.4/jquery.mobile-1.4.4.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.4/jquery.mobile-1.4.4.min.js"></script>
<script type="text/javascript" >
$( document ).ready(function() {
alert($( "input[myattr='navo']" ).val());
$( "input[myattr='navo']" ).val("Simon Commission");
alert($( "input[myattr='navo']" ).val());
});
</script>
</head>
<body>
<input type="text" myattr='navo' value="Morley Minto Reform" />
</body>
</html>
$( "input[myattr='navo']" ) returns a jQuery object, not a dom element so it doesn't have a property called value. You need to use the various methods provided by jQuery on the jQuery object.
In this case you can use the .val() method to get/set the value of an input element
$(document).ready(function() {
alert($("input[myattr='navo']").val());
$("input[myattr='navo']").val("Simon Commission");
alert($("input[myattr='navo']").val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="text" myattr='navo' value="Morley Minto Reform" />
Related
I need to change the text inside a dynamically generated p element after this element is from another script.
The adobe edge script creates two p elements inside #Stage. I need to change the text inside these p elements after they are created.
I actually can change the text with the on.("click") event but i need to fire this event as soon as the p elements are genereated.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<script src="https://code.jquery.com/jquery-3.2.1.js" integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" crossorigin="anonymous"></script>
<script type="text/javascript" charset="utf-8" src="edge_includes/edge.6.0.0.min.js"></script>
</head>
<body>
<div id="Stage">
</div>
<script type="text/javascript">
$( "#Stage" ).on( "click", "p", function() {
$("#Stage p").text("New Content");
});
</script>
</body>
</html>
Hope this helps:
$(function(){
$("<p></p>").appendTo($("#Stage"));
$("<p></p>").appendTo($("#Stage"));
$("<p></p>").appendTo($("#Stage"));
});
$("#Stage p").livequery(function () {
$("#Stage p").text("New Content");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/livequery/1.1.1/jquery.livequery.min.js"></script>
<div id="Stage"></div>
What I'm trying to do is when I update input text ID called foo it should be updated real time on input text id called goo. I already close to this solution I think but somehow it is not working. please check.
$('#foo').keyup(updatetxt);
$('#foo').keydown(updatetxt);
var foo = $('#foo');
function updatetxt() {
$('#goo').val(foo);
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js" type="text/javascript"></script>
<input type="text" id="foo" value="something">
<input type="text" id="goo" disabled="disabled" value="something">
You are assigning the element to val() whereas you need to update the value and that should happen into the function.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js" type="text/javascript"></script>
</head>
<body>
<input type="text" id="foo" value="something">
<input type="text" id="goo" disabled="disabled" value="something">
<script type='text/javascript'>
$('#foo').keyup(updatetxt);
//$('#foo').keydown(updatetxt);
//var foo = $('#foo').val();
function updatetxt() {
$('#goo').val($('#foo').val());
}
</script>
</body>
</html>
You were very close. You were just updating with the HTML element, instead of the HTML element value. Your updatetxt function should look like this:
var value = $(this).val();
$('#goo').val(value);
Here you go with a solution https://jsfiddle.net/pyvnkdc2/
$('#foo').keyup(function(){
$('#goo').val($(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="foo" value="something">
<input type="text" id="goo" disabled="disabled" value="something">
On keyup just assign the value to another input textbox.
I wanted save value in inputbox to JS variable, but when i save it, doesn't appear in console, why? thanks for advice
<!DOCTYPE html>
<html dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Color Picker</title>
<link href="color-picker.min.css" rel="stylesheet">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.3.min.js" ></script>
</head>
<body>
<p><input type="text"></p>
<script src="color-picker.min.js"></script>
<script>
var picker = new CP(document.querySelector('input'));
picker.on("change", function(color) {
this.target.value = '#' + color;
})
function colorpick() {
var el = document.querySelector('input');
console.log(el);
}
</script>
<input onclick="colorpick()" type="button" class="button" value="Submit">
</body>
</html>
I am not sure what are you trying to accomplish but colorpick function is only selector of the input element itself. You need console.log(el.value) instead.
I want to show datepicker in input box.4 days before This code show datepicker.Now I modified unknownly.I dont know What I changed.Here I attached my code
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="http://www.jscodes.com/codes/calendar_javascript/demo/css/datePicker.css" />
<script src="http://www.jscodes.com/codes/calendar_javascript/demo/js/jquery-1.6.1.min.js" type="text/javascript"></script>
<script src="http://www.jscodes.com/codes/calendar_javascript/demo/js/jquery.datePicker-min.js" type="text/javascript"></script>
<title>Content Delv Logs</title>
<script type="text/javascript">
$(window).ready(function() {
$('#date-pick').datePicker({clickInput: true});
});
</script>
</head>
<body>
<input type="text" name="date" id="date-pick" value=""/>
</body>
Add this link in your head tag. You are missing jQuery UI library:
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
$(function() {
$( "#datepicker" ).datepicker();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<p>Date: <input type="text" id="datepicker"></p>
use jquery UI with alot of functions and more to give;;;
http://jqueryui.com/
http://jqueryui.com/datepicker/
You just need to enable jQuery UI.
Have a look at this JSFiddle
$(function() {
$( "#datepicker" ).datepicker();
});
Please note how jQueryUI is enabled.
My options.html:
<!doctype html>
<html>
<head>
<title>Item Notifier v1.0.2</title>
<link href="style.css" rel="stylesheet" type="text/css">
<script src="jquery.js"></script>
<script src="options.js"></script>
</head>
<body>
<h1>Cowboy's Item Notifyer</h1>
<label>Last updated hat:<h2 id='itemname'>[ loading... ]</h2></label>
</body>
</html>
Then my options.js:
$(document).ready(function() {
$('#itemname').html() = localStorage.mostRecentHat;
});
It's supposed to change the innerHTML from [ loading... ] to the value of mostRecentHat but it turns up the value as undefined and doesnt change the innerHTML.
You should pass the value as a parameter to html method.
$(document).ready(function() {
$('#itemname').html(localStorage.mostRecentHat);
// document.getElementById('itemname').innerHTML = localStorage.mostRecentHat;
});