Posts

Showing posts with the label javascript-events

window.onload vs $(document).ready()

Image
window.onload vs $(document).ready() What are the differences between JavaScript's window.onload and jQuery's $(document).ready() method? window.onload $(document).ready() possible duplicate of $(document).ready equivalent without jQuery – Kzqai Mar 15 '15 at 14:34 14 Answers 14 The ready event occurs after the HTML document has been loaded, while the onload event occurs later, when all content (e.g. images) also has been loaded. ready onload The onload event is a standard event in the DOM, while the ready event is specific to jQuery. The purpose of the ready event is that it should occur as early as possible after the document has loaded, so that code that adds functionality to the elements in the page doesn't have to wait for all...

VueJS: For text input, how to make it so that clicking on it will select everything?

VueJS: For text input, how to make it so that clicking on it will select everything? I've found this: Copy to Clipboard that also works on Mobile? But VueJS doesn't use jQuery. So what is the alternative to this? 2 Answers 2 You can still use JQuery, just add the script to your HTML, but if you don't want to use JQuery the alternative is to use vanilla Javascript (pure JS). The setSelectionRange(start, end) method of an input is the answer you may want. setSelectionRange(start, end) Here's a demo. Working demo <input type="text" ref="input" @click="selectAll"> selectAll() { this.$refs.input.select(); } : https://jsfiddle.net/s7L895n7/14/ Welcome to Stack Overflow, please review: stackoverflow.com/help/how-to-answer – Daniel May 14 at 2:17 ...

How can I remove a class if the class has a value? [duplicate]

How can I remove a class if the class has a value? [duplicate] This question already has an answer here: I want to check if a class has a value. If the class has a value the text color "red" should be removed. At the moment it just works when i click into the input field. I've tried different on.(events) but I couldn't find the right one.... !Important! I do not want to check if someone made a input, just if the class has a value! $('.form-control-login').on('click', function() { $(this).parent().toggleClass('is-empty', this.value.trim().length == 0); }); .is-empty { color: red; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="form-group label-floating is-empty"> <label class="control-label">Your Email</label> <input class="form-control-login" value="test" name="login" autocomplete="user...