cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="button button--1">1</div>
<div class="button button--2">2</div>
<div class="button button--3">3</div>
<div class="button button--4">4</div>
<div class="button button--5">5</div>
<div class="button button--6">6</div>
            
          
!
            
              .button
	background-color: blue
	width: 100px
	height: 100px
	float: left

	&--2
		background-color: red
	
	&--3
		background-color: green
	&--4
		background-color: yellow

	&--5
		background-color: blue
	
	&--6
		background-color: red
            
          
!
            
              //参考 https://app.codegrid.net/entry/practical-jquery-1
//    http://www.jquerystudy.info/reference/events/currentTarget.html
//関数を呼び出すときは()無しで
$('.button--1').on('click', doAlert);

function doAlert (){
	alert("button");
}

//無名関数を記述し、それを実行
$('.button--2').on('click', function(){
	alert("無名関数");
});

//複数のイベントをスペースでつなぐことが出来る
$('.button--3').on('click mouseenter', function(){
	alert("green");
});

//$('セレクタ').on({'key1':value1, 'key2':value2, 'key3':value2 });
//連想配列=オブジェクトの表記

$('.button--4').on({
	'click' : function(){
		alert("click");
	},
	'mouseenter' : function(){
		alert("enter");
	}
});

//関数名を指定して、複数イベントを登録する
$('.button--5').on({
	'click' : doClick,
	'mouseenter' : doMouseEnter
});

function doMouseEnter(){
	alert("mouse enter");
}

function doClick(){
	alert("doCLick");
}

//イベントオブジェクトを、実行する関数に渡すことが出来る
//二番目の引数に、{key: 値}を与えると、関数が受け取ったevent.dataの下に入る。
//のでこの例で言えば、event.data.valueに3が入っている。
$('.button--6').on('click', {value: 3,test: 4 },doCount);

//eはjQueryオブジェクトだが、e.currentTargetは単なる文字列のようなので、
//それに対してjQueryファンクションを実行する場合には、$()でまずラップする必要がある
function doCount (e){
	console.log(e);
	alert("count: " + e.data.value);
	alert("test: " + e.data.test);
	let htmlContent = $(e.currentTarget).html();
	console.log(htmlContent);
}
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console