-4

I'm trying to paste in some code from codemyui.com into my website, but it looks like there's an error in the javascript. Can someone more familiar with javascript help me?

https://codepen.io/nenadkaevik/pen/odyrGm

var tabs = $('.tabs');
var selector = $('.tabs').find('a').length;
//var selector = $(".tabs").find(".selector");
var activeItem = tabs.find('.active');
var activeWidth = activeItem.innerWidth();
$(".selector").css({
  "left": activeItem.position.left + "px", 
  "width": activeWidth + "px"
});

$(".tabs").on("click","a",function(e){
  e.preventDefault();
  $('.tabs a').removeClass("active");
  $(this).addClass('active');
  var activeWidth = $(this).innerWidth();
  var itemPos = $(this).position();
  $(".selector").css({
    "left":itemPos.left + "px", 
    "width": activeWidth + "px"
  });
});

Dreamweaver says that in line two selector is assigned a value but never used and CodePen says that $ is not defined in the same place.

j08691
  • 204,283
  • 31
  • 260
  • 272
iWyn
  • 1

2 Answers2

0

$ is the abreviation of jQuery, you need to import de CDN script of jQuery into your scripts in order to make it work.

m4el
  • 455
  • 1
  • 4
  • 14
0

You can use the codepen settings to add the reference to the jQuery library. Click on the settings icon. Go to 'Add External Scripts/Pens' and choose the jQuery cdn link.

enter image description here

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Ran Turner
  • 14,906
  • 5
  • 47
  • 53