Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7865953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:14:27+00:00 2026-06-03T00:14:27+00:00

​<button id=test class=example whatever>Show classes</button>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ $(‘button’).click(function(){ var classes = $(this).attr(‘class’); alert(classes); });​ The above

  • 0
​<button id="test" class="example whatever">Show classes</button>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

$('button').click(function(){
  var classes = $(this).attr('class');
  alert(classes);
});​

The above code returns the content of the class attribute. How can I get it to return the classes formatted?

For instance, in this case, I want the variable classes to have a value of .example.whatever instead of example whatever.

I’ve searched and the only solution that seemed to be provided is the code I demonstrated above.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:14:28+00:00Added an answer on June 3, 2026 at 12:14 am

    I’m really very uneasy about this, since replacing spaces with periods will give the representation of stacked classes, when the classes aren’t really stacked, but here you go:

    // class="foo bar fiz buz" -> .foo.bar.fiz.buz
    this.className.replace( /^|\s/g , "." );
    

    Demo: http://jsbin.com/awitef/edit#javascript,html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<script> $(#test_img).click(function() { alert(Hello); }); </script> But it doesn't matter what mouse button I'm
I'm writing a test to verify location services are started when a button click
please note to this: public class test extended Jframe implement actionlistener{ test() { Jpanel
The sample page: <!DOCTYPE html> <html> <head> <meta charset=utf-8> <title>Button test</title> <style> * {
$(#button_title_delete).click(function(){ jQuery.ajax({type:'POST', url:'delete.php', data: 'id='+$(bid).val(), success: function(veri) { $(#delete_result).html(veri);} }); }); When i click
I have a the following selenium test suite inheriting from the same base class,
For example I want to execute something when user clicks on a button. Which
Why does FindName() return null in the following example? XAML: <Window x:Class=TestDynamicTextBox343.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
I have create in MySQdb a DB with a table named example,in this table
Hi I have a very simple integration test require 'integration_test_helper' Capybara.current_driver = :rack_test class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.