How can I select an element with multiple classes in jQuery?


Group Selector

body {font-size: 12px; }
body {font-family: arial, helvetica, sans-serif;}
th {font-size: 12px; font-family: arial, helvetica, sans-serif;}
td {font-size: 12px; font-family: arial, helvetica, sans-serif;}

Becomes this:

body, th, td {font-size: 12px; font-family: arial, helvetica, sans-serif;}
<element class="a b">
$(".a.b")

Toggle between multiple div’s or similar to tabs


Toggling between multiple divs with similar tab. No bootstrap included within this code

$(document).ready(function() {
$('.nav-tabs > li > a').click(function(event){
event.preventDefault();

//get displaying tab content jQuery selector
var active_tab_selector = $('.nav-tabs > li.active > a').attr('href');

//find actived navigation and remove 'active' css
var actived_nav = $('.nav-tabs > li.active');
actived_nav.removeClass('active');

//add 'active' css into clicked navigation
$(this).parents('li').addClass('active');

//hide displaying tab content
$(active_tab_selector).removeClass('active');
$(active_tab_selector).addClass('hide');

//show target tab content
var target_tab_selector = $(this).attr('href');
$(target_tab_selector).removeClass('hide');
$(target_tab_selector).addClass('active');
});
});

DEMO
http://jsbin.com/mozeyo

Save html form input to json file


Using Serializing we can save input html form to JSON output

<script type="text/javascript">
  $(document).ready(function() {
  $("#btn").click(function(e){
     var jsonData = {};

   var formData = $("#myform").serializeArray();
  // console.log(formData);

   $.each(formData, function() {
        if (jsonData[this.name]) {
           if (!jsonData[this.name].push) {
               jsonData[this.name] = [jsonData[this.name]];
           }
           jsonData[this.name].push(this.value || '');
       } else {
           jsonData[this.name] = this.value || '';
       }


   });
   console.log(jsonData);
    $.ajax(
    {
        url : "action.php",
        type: "POST",
        data : jsonData,

    });
    e.preventDefault(); 
});
});
</script>

HTML

<div id="header">
 Send Form's data as JSON
</div>

<form id="myform" type="post">
  <fieldset>
    <legend>Ajax Form  </legend>
    <p>We would love to hear from you. Please fill out this form</p>
    <div class="elements">
      <label for="name">Name :</label>
      <input  required="required" type="text"  value="Girish Kumar Santhu" name="fname"  size="20"  />
    </div>
     <div class="elements">
      <label for="Age">Age :</label>
      <input required="required" type="number" value="32" id="age" name="age" size="10" />
    </div>  
    <div class="elements">
      <label for="pro"> Profession :</label>
      <select name="pro">
   <option value="Student">Student</option>
   <option value="Engineer" selected="selected">Engineer</option>
   </select>
    </div>      
    <div class="elements">
    <label for="Gender">Gender: </label>
      <input type="radio" name="gender" value="Male" checked="checked" id="r1"> Male 
  <input type="radio" name="gender" value="Female" id="r2"> Female 
</div>  
    <div class="elements">
      <label for="hobby">Hobby :</label>
      <input type="checkbox" name="hobby[]" value="Sports" id="ch1" checked="checked"> Sports 
  <input type="checkbox" name="hobby[]" value="Coding"  id="ch2"> Coding 
   </div>

    <div class="submit">
       <input type="submit" id="btn" name="btn" class="btn" value="Submit" />
    </div>
    <span class="elements">Press "Ctrl + Shift + J" to see sent JSON in console: <span>
  </fieldset>
</form>

DEMO

http://jsbin.com/kifozu/

Javascript getElementsByName.value not working


Here is the example for having one or more checkboxes value. If you have two or more checkboxes and need values then this would really help.

function myFunction() {
  var selchbox = [];
  var inputfields = document.getElementsByName("myCheck");
  var ar_inputflds = inputfields.length;

  for (var i = 0; i < ar_inputflds; i++) {
    if (inputfields[i].type == 'checkbox' && inputfields[i].checked == true)
      selchbox.push(inputfields[i].value);
  }
  return selchbox;

}

document.getElementById('btntest').onclick = function() {
  var selchb = myFunction();
  console.log(selchb);
}
Checkbox:
<input type="checkbox" name="myCheck" value="UK">United Kingdom
<input type="checkbox" name="myCheck" value="USA">United States
<input type="checkbox" name="myCheck" value="IL">Illinois
<input type="checkbox" name="myCheck" value="MA">Massachusetts
<input type="checkbox" name="myCheck" value="UT">Utah

<input type="button" value="Click" id="btntest" />

DEMO
https://jsfiddle.net/ssuryar/pn92429e

How to disable angular-ui bootstrap tabs?


A checkbox added to disable the tab using scope.

If checkbox is true then a function is been triggered, which assigns the value of scope to class attribute {{btnClass}}. By conditional statement in data-toggle we can set this attribute.

data-toggle=”{{btnClass == ‘disabled’ ? ” : ‘tab’}}”

HTML

<input type="checkbox" ng-model="vm.target[isselected]" name="" ng-click="checkbox(isselected)"> TARGET ALL USERS



    <ul class="nav nav-tabs tabs-left" role="tablist">
  <span class="navTitle">TARGET GROUP</span><!-- 'tabs-right' for right tabs -->
    <li class="active" role="presentation"><a href='' data-target="#everyone" aria-controls="everyone" data-toggle="tab">EVERYONE</a></li>
<li class="{{btnClass}}"><a href='' data-target="#userprofile" aria-controls="userprofile" data-toggle="{{btnClass == 'disabled' ? '' : 'tab'}}">USER PROFILE</a></li>
<li class="{{btnClass}}"><a href='' data-target="#customergroup" aria-controls="customergroup" data-toggle="{{btnClass == 'disabled' ? '' : 'tab'}}">CUSTOMER GROUP</a></li>
<li class="{{btnClass}}"><a href='' data-target="#customer" aria-controls="customer" data-toggle="{{btnClass == 'disabled' ? '' : 'tab'}}">CUSTOMER</a></li>
<li class="{{btnClass}}"><a href='' data-target="#catalog" aria-controls="catalog" data-toggle="{{btnClass == 'disabled' ? '' : 'tab'}}">CATALOG</a></li>
<li class="{{btnClass}}"><a href='' data-target="#customerwarehouse" aria-controls="customerwarehouse" data-toggle="{{btnClass == 'disabled' ? '' : 'tab'}}">CUSTOMER WAREHOUSE</a></li>
  </ul>

Angularjs

$scope.checkbox = function(isselected) {
if (vm.target[isselected]) {
$scope.btnClass = "disabled";
}
else {
  $scope.btnClass = "";
}
};

Disable Proximity Sensor during call


Proximity Sensor Dial

*#*#7378423#*#*

1) Service Tests – (If present)

2) Proximity Switch

3) Test on sensor (Next to logo(top) of mobile)

4) Yes if works, then u can keep on and proximity switch forever which gives beep all the time and consumes lot of battery

OR

4) No it doesn’t work – Then simply clean the mobile screen or screen guard and clear the blocked screen from sensor. It works charm.

Technically, Its not any software solution, but hardware solution will work.

Bind ng-options value and label to ng-model


<div ng-app="app">
<div ng-controller="ctrl">
     <select ng-model="selected" ng-options="opt as opt.language for opt in tableResult.locales"></select>        
     <p>You have selected {{ selected.language }}</p>
     <p>You havd id too! {{ selected.localeId }}</p>
     <p>
     </p>
     <input type="text" value="{{selected.localeId}} : {{selected.language}}" style="width:50%;"/>

</div>

DEMO
http://jsfiddle.net/e8mth5tb/135/

Loading jQuery in WordPress backend getting error: “jQuery is not defined”


FTP of your site and open up your wp-config.php file.
Add this line:

define('CONCATENATE_SCRIPTS', false);

Make sure you add this before:

/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
        define('ABSPATH', dirname(__FILE__) . '/');

Hopefully this helps you to save a day on WordPress installation

How to make tinymce works in development and dist environment using grunt?


In Gruntfile.js

// Copies remaining files to places other tasks can use
copy: {
            dist: {
                files: [{
                    expand: true,
                    dot: true,
                    cwd: '<%= yeoman.app %>',
                    dest: '<%= yeoman.dist %>',
                    src: [
                        '*.{ico,png,txt}',
                        '.htaccess',
                        '*.html',
                        'modules/**/*.html',
                        'images/{,*/}*.*',
                        'styles/fonts/{,*/}*.*'
                    ]
                }, {
                    expand: true,
                    cwd: '.tmp/images',
                    dest: '<%= yeoman.dist %>/images',
                    src: ['generated/*']
                }, {
                    expand: true,
                    cwd: 'bower_components/bootstrap-sass-official/assets/fonts/bootstrap/',
                    src: '*',
                    dest: '<%= yeoman.dist %>/fonts'
                }, {
                    expand: true,
                    cwd: 'bower_components/tinymce-dist/themes/modern/',
                    src: ['**'],
                    dest: '<%= yeoman.dist %>/core/themes/modern/'
                }, {       
                    expand: true,
                    cwd: 'bower_components/tinymce-dist/skins/',
                    src: ['**'],
                    dest: '<%= yeoman.dist %>/core/skins/'
                }, {
                    expand: true,
                    cwd: 'bower_components/tinymce-dist/plugins/link/',
                    src: ['**'],
                    dest: '<%= yeoman.dist %>/core/plugins/link/'
                }, {
                    expand: true,
                    cwd: 'bower_components/font-awesome/fonts/',
                    src: '*',
                    dest: '<%= yeoman.dist %>/fonts'
                }]
            },
            styles: {
                expand: true,
                cwd: '<%= yeoman.app %>/modules',
                dest: '.tmp/styles/',
                src: '{,*/}*.css'
            }
        },