Vertically centering Bootstrap modal window

I would like to center my modal on the viewport (middle) I tried to add some css properties .modal { position: fixed; top:50%; left:50%; } I’m using this example http://jsfiddle.net/rniemeyer/Wjjnd/ I tried $(“#MyModal”).modal(‘show’).css( { ‘margin-top’: function () { return -($(this).height() / 2); }, ‘margin-left’: function () { return -($(this).width() / 2); } }) 31 Answers … Read more

How do I replace text inside a div element?

I need to set the text within a DIV element dynamically. What is the best, browser safe approach? I have prototypejs and scriptaculous available. <div id=”panel”> <div id=”field_name”>TEXT GOES HERE</div> </div> Here’s what the function will look like: function showPanel(fieldName) { var fieldNameElement = document.getElementById(‘field_name’); //Make replacement here } 14 Answers 14

How to run JavaScript function in WooCommerce checkout?

I’m building reCAPATCHA into my WooCommerce checkout. It is a fairly easy process as I’m using woocommerce_checkout_process to validate the capatcha. However, I have running into one issue. When there is a cart error, I want to be able to reset the reCAPATCHA using grecaptcha.reset(); JavaScript function. I’m unsure how to run the JavaScript command … Read more

Dynamically load a JavaScript file

How can you reliably and dynamically load a JavaScript file? This will can be used to implement a module or component that when ‘initialized’ the component will dynamically load all needed JavaScript library scripts on demand. The client that uses the component isn’t required to load all the library script files (and manually insert <script> … Read more

Turn jQuery.ajax() request into XMLHttpRequest (vanilla JavaScript)

Been looking for some help changing a jQuery.ajax() request into vanilla XMLHttpRequest for WordPress, but not really finding what I want. Can anyone help me reformat the below into vanilla JavaScript XMLHttpRequest? $.ajax({ data: { ‘action’: ‘work_hour_form_handler’, ‘work_hours_start’: document.getElementById(‘work-hours–start’).value, ‘work_hours_end’: document.getElementById(‘work-hours–end’).value, ‘break-hours_start’: document.getElementById(‘break-hours–start’).value, ‘break-hours_duration’: document.getElementById(‘break-hours–duration’).value, ‘working_days’: document.getElementById(‘working-days’).value }, headers: {}, method: ‘post’, url: fpm_ajax.ajax_url }).done(function … Read more

Is it possible to send a variable number of arguments to a JavaScript function?

Is it possible to send a variable number of arguments to a JavaScript function, from an array? var arr = [‘a’,’b’,’c’] var func = function() { // debug alert(arguments.length); // for(arg in arguments) alert(arg); } func(‘a’,’b’,’c’,’d’); // prints 4 which is what I want, then ‘a’,’b’,’c’,’d’ func(arr); // prints 1, then ‘Array’ I’ve recently written … Read more