Using jQuery To Get Size of Viewport
To get the width and height of the viewport: var viewportWidth = $(window).width(); var viewportHeight = $(window).height(); resize event of the page: $(window).resize(function() { });
To get the width and height of the viewport: var viewportWidth = $(window).width(); var viewportHeight = $(window).height(); resize event of the page: $(window).resize(function() { });
According to MDN, Preflighted requests Unlike simple requests (discussed above), “preflighted” requests first send an HTTP OPTIONS request header to the resource on the other domain, in order to determine whether the actual request is safe to send. Cross-site requests are preflighted like this since they may have implications to user data. In particular, a … Read more
HTML <div id=”mydiv” data-myval=”10″></div> JS var a = $(‘#mydiv’).data(‘myval’); //getter $(‘#mydiv’).data(‘myval’,20); //setter Demo Reference From the reference: jQuery itself uses the .data() method to save information under the names ‘events’ and ‘handle’, and also reserves any data name starting with an underscore (‘_’) for internal use. It should be noted that jQuery’s data() doesn’t change … Read more
Say you had radio buttons like these, for example: <input type=”radio” name=”gender” value=”Male”> <input type=”radio” name=”gender” value=”Female”> And you wanted to check the one with a value of “Male” onload if no radio is checked: $(function() { var $radios = $(‘input:radio[name=gender]’); if($radios.is(‘:checked’) === false) { $radios.filter(‘[value=Male]’).prop(‘checked’, true); } });
You can set the year range using this option per documentation here http://api.jqueryui.com/datepicker/#option-yearRange yearRange: ‘1950:2013′, // specifying a hard coded year range or this way yearRange: “-100:+0″, // last hundred years From the Docs Default: “c-10:c+10” The range of years displayed in the year drop-down: either relative to today’s year (“-nn:+nn”), relative to the currently … Read more
You can use the input Javascript event in jQuery like this: $(‘#inputDatabaseName’).on(‘input’,function(e){ alert(‘Changed!’) }); In pure JavaScript: document.querySelector(“input”).addEventListener(“change”,function () { alert(“Input Changed”); }) Or like this: <input id=”inputDatabaseName” onchange=”youFunction();” onkeyup=”this.onchange();” onpaste=”this.onchange();” oninput=”this.onchange();”/>
You can add attributes using attr like so: $(‘#someid’).attr(‘name’, ‘value’); However, for DOM properties like checked, disabled and readonly, the proper way to do this (as of JQuery 1.6) is to use prop. $(‘#someid’).prop(‘disabled’, true);
Thanks Attack. I wanted to use jQuery. You pointed me in the right direction, and this is what I ended up with: Here is a link to the plugin: https://plugins.jquery.com/textfill/ And a link to the source: http://jquery-textfill.github.io/ ;(function($) { $.fn.textfill = function(options) { var fontSize = options.maxFontPixels; var ourText = $(‘span:visible:first’, this); var maxHeight = … Read more
If you don’t want use timer and check innerHTML you can try this event $(‘mydiv’).on(‘DOMSubtreeModified’, function(){ console.log(‘changed’); }); More details and browser support datas are Here.
$(‘a[data-toggle=”tab”]’).on(‘shown.bs.tab’, function (e) { var target = $(e.target).attr(“href”) // activated tab alert(target); }); <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js”></script> <script src=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js”></script> <link href=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css” rel=”stylesheet”/> <ul id=”myTab” class=”nav nav-tabs”> <li class=”active”><a href=”#home” data-toggle=”tab”>Home</a></li> <li class=””><a href=”#profile” data-toggle=”tab”>Profile</a></li> </ul> <div id=”myTabContent” class=”tab-content”> <div class=”tab-pane fade active in” id=”home”> home tab! </div> <div class=”tab-pane fade” id=”profile”> profile tab! </div> </div>