Knockout Doesn't work on Fiddle [closed] - javascript

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 8 years ago.
Improve this question
The following code does not work on jsFiddle even when have set the correct Framework and extension, i.e. jquery 1.7.2 and no-wrap in body.
HTML Code
Name:<input data-bind="value: name" />
<p>Hello, <span data-bind="text: name"></span></p>
<button data-bind="click: changeName">Change Name</button>
Javascript Code
$(function () {
var viewModel = {
name: ko.observable("bob"),
changeName: function () {
this.name("steve");
}
};
ko.applyBindings(viewModel);
});

Make sure you have included jQuery as well as KnockoutJS library while creating your JSFiddle. One of them will be in external resources section on left sidebar because JSFiddle does not provide feature to include both at one go in frameworks and extensions section..
http://jsfiddle.net/yLcqd06q/1/
$(function(){
var viewModel = {
name: ko.observable("bob"),
changeName: function () {
this.name("steve");
}
};
ko.applyBindings(viewModel);
});
Tip for you : Always mention the error you get in console while posting such questions :-)
Hope that helps..
Peace, RP

Related

How To Disable Scrolling During Loading? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I'm working on my personal website and have implemented a preloader.
After adding a second div to my website, I noticed I can scroll during the page loading. I dunno about you but I find that ugly and disturbing.
Here is a quick video. (I use chromeOS)
Video
I really couldn't find anything on this because I think I was the only one with this problem. I'm not sure, however.
I used $(window).on("load",function(){$(".loader-wrapper").fadeOut("slow");}); as well
Here is the code (Github Repo)
Anyways, that's all I got.
Thanks in advance.
You can add by default a class to your body the class should be as follows.
// CSS
.no-scroll {
overflow: hidden;
}
<body class="no-scroll">
Once your script has completed or your function finishes you just call
document.body.classList.remove('no-scroll');
Make sure to add the following section at the end of your page.
<script type="text/javascript">
(function(){
function onReady() {
document.body.classList.remove('no-scroll');
}
if ( document.readyState === 'complete' ) {
onReady();
} else {
document.addEventListener('DOMContentLoaded', onReady);
}
})();
</script>
Or you can do it with jQuery
// Make sure this code is the last piece of code in your HTML.
$(window).on("load", function() {
document.body.classList.remove('no-scroll');
});
PS: Additionally to that consider the unlike scenario when someone does not have JavScript enabled so you add a default behavior. Take a look at <noscript> tag.

How to change this javascript function to Jquery [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have this code to work as character limiter for CKEditor, but its old and i dont know why does not work when i use Jquery librarie in the same web site
window.onload = function() {
CKEDITOR.instances.aqui.on( 'key', function() {
var str = CKEDITOR.instances.aqui.getData();
var regex = /(<([^>]+)>)/ig
, result = str.replace(regex, "");
if (result.length > 50) {
CKEDITOR.instances.aqui.setData(str);
}
} );
};
i want to update the code to use Jquery, but i dont know to much of jquery and i think if i use this function (replace, remove or text that) it will be more usefull
The code works if you dont add the Jquery library.
If you are using CKEditor, you may need the jQuery Adapter to make it work.
You will need include source files like this on your header
<script src="jquery.js"></script>
<script src="ckeditor.js"></script>
<script src="adapters/jquery.js"></script>
Please see details here
You are overwriting the windows.onload event handler and that should be the cause of your problem.
Try instead the following change in your code:
// previous
window.onload = function() { /* your code here */ };
// suggestion
$( document ).ready(function() { /* your code here */ });

jQuery script won't run [closed]

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 8 years ago.
Improve this question
I have a jQuery function that basically toggles a div on click but it doesn't work I can't tell if I maybe imported the library incorrectly or what but I can't get it to function at all. Please tell me if I am missing anything or messed up my code somewhere.
My exact code looks like this:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("a.notifications-dropdown-trigger").click(function () {
$('#post-notifications-dropdown').toggle('slide', {
duration: 100,
direction: 'up'
});
});
});
</script>
The HTML markup:
<a class="notifications-dropdown-trigger">click me</a>
<div id="post-notifications-dropdown">
.... code
</div>
Everything is coded directly onto servers and is live the moment I save.
You can simply use .slideToggle()
Description: Display or hide the matched elements with a sliding motion.
Code
$(document).ready(function(){
$("a.notifications-dropdown-trigger").click(function (event) {
$('#post-notifications-dropdown').slideToggle(100);
event.preventDefault();
});
});

Running a javascript from an html button [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have an external javascript that I need to run on a button click. How would I go about doing that?
<script type='text/javascript' src='http://tracking.somedomain.com/include.js?
domain=www.somedomain.com'></script>
<script type='text/javascript' >
if(typeof sWOTrackPage=='function')sWOTrackPage();
</script>
I need this to run on the click of an html button. Any suggestions?
Pure JavaScript:
document.getElementById('theIDofYourButton').onclick = function() {
//your code here
}
jQuery:
$('#theIDofYourButton').click(function() {
//your code here
});
You can use addEventListener():
// Assuming the button has an id of 'btn':
var btn = document.getElementById('btn');
btn.addEventListener("click", function()
{
// Your code.
//
});
If you need support for older browsers, check out the older way to register event listeners.
try something like this:
HTML:
<input type="button" value="Do" id="doer" />
JS:
document.getElementById("doer").onclick = function() {
if(typeof sWOTrackPage=='function') sWOTrackPage();
}
The latter Javascript isn't practice-perfect, but that's not really the point here.
If you have any questions about how this was done, please ask away in the comments
Simplest answer. Use the onclick attribute on your HTML button

The Click event is not working. I can figure this out? [closed]

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 can't seem to get my click trigger to work.
I've tried the following:
//Handle the Main Menu Button Press
$("button").click( function() {
alert('yep');
});
And I never get the alert when I click any button on my site....
Where did I go wrong?
might be one of these:
- you forgot to include jQuery.js script in your header
- you didn't wait till DOM loaded
try:
$( function() {
$("button").click( function() {
alert('yep');
});
});
Your code works just fine. Here is a fiddle
You need to ensure you have jQuery loaded, you have waited for the DOM to load using
$(function() {
//your code here
});
And if you have multiple buttons, you will need to use CSS selectors to differentiate.
I would HIGHLY suggest you read this document, provided by jQuery
The HTML could be
<button type="button" name="btnOk" id="btnOk">ok</button>
The jQuery code could be
$("button[type='button']").click(function(){
alert("yeap");
});
or
$("button[name='btnOk']").click(function(){
alert("yeap");
});
If HTML is
<input type="button" name="btnOk" id="btnOk" value="Ok"/>
the code could be
$("input[type='button']").click(function(){
alert("yeap");
});
At first, be sure that :has the jquery code in
$(document).ready(function(){
//jquery code
});

Categories