how to get the class name dynamically using jquery code example

Example 1: how to get the class name dynamically using jquery

var classArray = $('input').attr('class').split(' ');
// So now you can declare variables
var classbtn1 = classArray[0];
var classbtn2 = classArray[1];

Example 2: how to get the class name dynamically using jquery

$('.'+$classOfBtn)

Example 3: how to get the class name dynamically using jquery

$(document).ready(function () {
    var $allClasses = $("[name='submit']").attr('class').split(' ');
    for(var i=0; i < $allClasses.length; i++)
    {
        // Check $allClasses[i] here.
    }
});

Example 4: how to get the class name dynamically using jquery

<input id="btn" class="wpsc-buy-now-button wpsc-buy-now-button-64" type="image"
    name="submit" border="0" src="https://www.paypal.com/en_US/i/btn/btn_buynow_LG.gif"
    alt="PayPal - The safer, easier way to pay online" />

Example 5: how to get the class name dynamically using jquery

$('.setvalue').on('click', function() {
       var id = $(this).data("id");
       var inp =  $('#applicantstatus_' + id).val();

Example 6: how to get the class name dynamically using jquery

$('.' + $classOfBtn) //note the dot

Example 7: how to get the class name dynamically using jquery

var className = $('#id').attr('class');

Example 8: how to get the class name dynamically using jquery

$(document).ready(function () {
    var $classOfBtn = $('#btn').attr('class').split(' ')[0] + '-64';
    alert($classOfBtn );
});

Example 9: how to get the class name dynamically using jquery

var id = $(this).attr("id")

Example 10: how to get the class name dynamically using jquery

var $classOfBtn = wpsc-buy-now-button-64;

Tags:

Misc Example