jquery

Modify countdown script to allow for multiple countdowns per page

梦想的初衷 提交于 2021-02-04 18:39:48
问题 I am utilizing the following script from CodePen // Create Countdown var Countdown = { // Backbone-like structure $el: $('.countdown'), // Params countdown_interval: null, total_seconds : 0, // Initialize the countdown init: function() { // DOM this.$ = { hours : this.$el.find('.bloc-time.hours .figure'), minutes: this.$el.find('.bloc-time.min .figure'), seconds: this.$el.find('.bloc-time.sec .figure') }; // Init countdown values this.values = { hours : this.$.hours.parent().attr('data-init

Modify countdown script to allow for multiple countdowns per page

走远了吗. 提交于 2021-02-04 18:39:31
问题 I am utilizing the following script from CodePen // Create Countdown var Countdown = { // Backbone-like structure $el: $('.countdown'), // Params countdown_interval: null, total_seconds : 0, // Initialize the countdown init: function() { // DOM this.$ = { hours : this.$el.find('.bloc-time.hours .figure'), minutes: this.$el.find('.bloc-time.min .figure'), seconds: this.$el.find('.bloc-time.sec .figure') }; // Init countdown values this.values = { hours : this.$.hours.parent().attr('data-init

How can I trigger an event when this span value changes?

对着背影说爱祢 提交于 2021-02-04 18:39:25
问题 I'm trying to get a console log when the price of the current page's stock changes. page: https://www.google.com/finance?q=NASDAQ%3AGOOG&ei=yvbRVbHSCcKgmAGyu7CoDA Element ID: #price-panel > div > span > span Attempt 1: fail $("#price-panel div span span").onchange = function() { console.log('change')} Attempt 2: fail document.getElementById('price-panel').children[0].children[0].onchange = function() { console.log('change')} builtwith.com says the javascript is the "google api" which is

How can I assign a unique ID to all div's that have a specific class using JQuery

孤者浪人 提交于 2021-02-04 18:29:52
问题 I am trying to add a unique ID to each div with the class of "owl-item". I would like the ID's to go in number order if possible starting with <div id="slide-1"... and so on. I can't seem to target the "owl-item" div's but only the div's inside of "owl-item" that have no ID or class assigned. How can I modify my javascript to achieve this? I cannot modify the html. HTML <div id="sample_slider" class="owl-carousel owl-pagination-true autohide-arrows owl-theme" style="opacity: 1; display: block

How can I assign a unique ID to all div's that have a specific class using JQuery

半腔热情 提交于 2021-02-04 18:29:51
问题 I am trying to add a unique ID to each div with the class of "owl-item". I would like the ID's to go in number order if possible starting with <div id="slide-1"... and so on. I can't seem to target the "owl-item" div's but only the div's inside of "owl-item" that have no ID or class assigned. How can I modify my javascript to achieve this? I cannot modify the html. HTML <div id="sample_slider" class="owl-carousel owl-pagination-true autohide-arrows owl-theme" style="opacity: 1; display: block

how to set width relative to grandparent elements not direct parent elements?

不问归期 提交于 2021-02-04 18:17:00
问题 i'm trying to set some elements' width with percentage relative to grandparent elements' width. like this. <style> .grand{width:1000px; overflow:hidden;} .parent{width:2000px; position:relative} .child1{float:left; width:50%; height:200px; background-color:blue;} .child2{float:left; width:50%; height:200px; background-color:green;} </style> <div class="grand"> <div class="parent"> <div class="child1"></div> <div class="child2"></div> </div> </div> But i have no idea how to make this done, how

Javascript regexObj.exec() says TypeError: pattern.exec is not a function

梦想与她 提交于 2021-02-04 18:15:57
问题 I want to extract image name from img tag with regex in javascript . My problem is that console.log() throws Exception: TypeError: pattern.exec is not a function . JS: $("label.btn-danger").on('click',function(e){ e.preventDefault(); var src = $(this).parents("label").find("img").attr("src"); var pattern = "/\/([A-Z0-9_-]{1,}\.(?:png|jpg|gif|jpeg))/ig"; var result = pattern.exec(src) console.log(result); }); 回答1: var pattern = "/\/([A-Z0-9_-]{1,}\.(?:png|jpg|gif|jpeg))/ig"; Creates a string.

How can one select specific sibling of a context node using jQuery?

不问归期 提交于 2021-02-04 18:10:48
问题 How can one select a specific sibling of a context node using jQuery? Specifically, given context node myContextNode select the sibling span with class myClass . document.evaluate("../span[@class='myClass']", myContextNode, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null). singleNodeValue; 回答1: You can use .siblings() with a selector, like this: $(myContextNode).siblings("span.myClass") 来源: https://stackoverflow.com/questions/2569699/how-can-one-select-specific-sibling-of-a-context-node-using

How to keep placeholder visible when user is typing first substring of the placeholder text

流过昼夜 提交于 2021-02-04 17:29:25
问题 Usually when we use input placeholder, the placeholder text will disappear as soon as the user type something. I'm thinking to give user an random example on input so user can mimic using placeholder. The problem is that, when user type something, the example will disappear. Is there any way to keep the placeholder visible when user type the beginning part of the placeholder text? Here's an example The placeholder text is 'Lorem ipsum dolor sit amet'. When user types 'Lorem ipsum', I assume

How to use jquery-validate localization

社会主义新天地 提交于 2021-02-04 16:46:34
问题 Is there a way to dynamically (i.e. from JS code) set/change the language of error messages, using the existing translations available in the repo? Non-solution #1 : Loading a localization script ( <script type="text/javascript" src="localization/messages_XX.js"> ) won't work because it cannot be changed on the client-side. Non-solution #2 : Setting custom messages with setDefaults requires me to come up with my own strings instead of reusing the existing ones. 回答1: Use jQuery $.extend() to