We’ve got a few pages using ajax to load in content and there’s a few occasions where we need to deep link into a page. Instead of having a link to “Users” and telling people to click “settings” it’s helpful to be able to link people to user.aspx#settings To allow people to provide us with correct links to sections (for
Tag: jquery
Resetting a setTimeout
I have the following: How can I, via a .click function, reset the counter midway through the countdown? Answer You can store a reference to that timeout, and then call clearTimeout on that reference.
How do I set/unset a cookie with jQuery?
How do I set and unset a cookie using jQuery, for example create a cookie named test and set the value to 1? Answer Update April 2019 jQuery isn’t needed for cookie reading/manipulation, so don’t use the original answer below. Go to https://github.com/js-cookie/js-cookie instead, and use the library there that doesn’t depend on jQuery. Basic examples: See the docs on
Disable/enable an input with jQuery?
or Which is the standard way? And, conversely, how do you enable a disabled input? Answer jQuery 1.6+ To change the disabled property you should use the .prop() function. jQuery 1.5 and below The .prop() function doesn’t exist, but .attr() does similar: Set the disabled attribute. To enable again, the proper method is to use .removeAttr() In any version of
How do I prevent a parent’s onclick event from firing when a child anchor is clicked?
I’m currently using jQuery to make a div clickable and in this div I also have anchors. The problem I’m running into is that when I click on an anchor both click events are firing (for the div and the anchor). How do I prevent the div’s onclick event from firing when an anchor is clicked? Here’s the broken code:
JavaScript moving element in the DOM
Let’s say I have three <div> elements on a page. How can I swap positions of the first and third <div>? jQuery is fine. Answer Trivial with jQuery If you want to do it repeatedly, you’ll need to use different selectors since the divs will retain their ids as they are moved around.
jQuery hover(): mouseout does not fire when using overflow:auto (with scrollbars)
I’m using jQuery’s hover() helper to attach some behavior to <li> elements in a <ul> with max-height and overflow:auto CSS properties. When the height of the <ul> goes beyond max-height and the vertical scrollbar appears, hovering over the <li> elements triggers mouseOver, but if I move to the right to the scrollbar and start scrolling with the mouse, the mouseOut
How to create a jQuery plugin with methods?
I’m trying to write a jQuery plugin that will provide additional functions/methods to the object that calls it. All the tutorials I read online (have been browsing for the past 2 hours) include, at the most, how to add options, but not additional functions. Here’s what I am looking to do: //format div to be a message container by calling
Javascript / jQuery: How to prevent active input field from being changed?
how do I prevent the user to change the value in an input field (which contains a certain value to be copied into the clipboard) without using disabled=”true”? The text should be selected once the user clicks in the field (that’s working already) but entering anything should have no effect. Thanks Answer readonly in the html of the input is
How do you get the length of a string?
How do you get the length of a string in jQuery? Answer You don’t need jquery, just use yourstring.length. See reference here and also here. Update: To support unicode strings, length need to be computed as following: or create an auxiliary function