[email protected]      beta
Donate

How to get classname of selected element in jquery

 jQuery .attr(): This article explain how to get class name or Fetch class name of element i.e Div, UL, li or any other HTML tag. You can also check my previous post on Learn jQuery, where have explained how to add click event on dynamically added element, and how to preview image before upload on server.

HTML:

Add div tags, with some class.

//*
<div id="content" class="foo boo">
  Click Me
</div>
//*

jQuery: code to get class name on button click

//*
$("#content").on('click',function(){
  var getClassName=$(this).attr("class");
  alert(getClassName);
});
//*

 

Share:    
Satinder Singh

Hi all, am Founder and Author of Codepedia.info, also atypical polyglot programmer from Bombay, India. I have a passion to create, solve, and deploy software applications.
       ForEach ( minute in MyLife ) { myExperience++ ; }



Post Comment


Your email address will not be published. Required fields are marked *