Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //===============================================================================
- // JavaScript snippets
- // document loaded listener
- document.addEventListener("DOMContentLoaded", addDocumentListeners);
- // Create Selectors
- const processBtn = document.querySelector("#processBtn")
- // Hide an adjacent element via DOM and CSS
- nameSelector.nextElementSibling.classList.add("hide");
- // set radio button checked item
- document.querySelector("#city-none").checked = true;
- // get value for which item is checked in radio buttons
- document.querySelector('input[name="city"]:checked').value;
- // add click event listener
- processBtn.addEventListener("click", validateFunction)
- // shortcut to target any item inside a div
- const toggleFunction = e =>{
- e.currentTarget.parentNode.children[1].classList.toggle("hide");
- e.currentTarget.parentNode.children[2].classList.toggle("hide");
- e.currentTarget.parentNode.children[3].classList.toggle("hide");
- e.currentTarget.parentNode.children[4].classList.toggle("hide");
- }
- //jQuery Quick Reference
- //=============================================================================
- // document ready check
- $(document).ready(
- () => {
- functionName();
- }
- )
- // Regex check
- const locationSelector = document.querySelector("#locationID");
- letregexTest = /^[1-9][0-9]{5}$/.test(locationSelector.value);
- // Getting values from a form field in jquery
- $("[name='name']").val(name);
- const radio1 = $("#radio1");
- const radio2 = $("#radio2");
- const radioOutputField = $("#radioOuput");
- $("#btnTarget").click(
- evt => {
- if (radio1.is(":checked")){
- radioOutputField.val("Message 1");
- }
- else if (radio2.is(":checked")){
- radioOutputField.val("Message2")
- }
- }
- // round to 2 decimals
- numberVar.toFixed(2)
- // Radio Button to textbox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement