CSS Apprentice CSS Apprentice - 1 year ago 61
Javascript Question

How To Convert A className Into An ID in jQuery

In my example I have a basic tabbed content setup. The buttons have classes that match the divs IDs. onClick, I'd like to grab the className, and find an ID with the same name

enter image description here


$("li").click(function() {
var liClass = this.className;

jsFiddle: https://jsfiddle.net/CSS_Apprentice/kpo7t6xh/

Answer Source

Here's what's wrong:


Should be:


The `.active class was on the divs not the lis.