Skip to content

Instantly share code, notes, and snippets.

@avireni
avireni / index.html
Last active April 12, 2024 02:55
CSS3 Flexbox
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='styles.css'/>
</head>
<body>
<div class="flex-container">
<div class="flex-item">Item 1</div>
<div class="flex-item">Item 2</div>
<div class="flex-item">Item 3</div>
@avireni
avireni / gist:2877304
Last active October 5, 2015 21:08
HTML Manipulation with jquery
Changing Content of HTML through jQuery
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("p").html("Change the content with jQuery");
});
@avireni
avireni / jquery.snippets.js
Created April 17, 2012 00:05 — forked from eapen/jquery.snippets.js
Jquery + JS snippets
Check if and which key was pressed
$(function() {
$(document).keypress(function(e){
switch(e.which){
// "ENTER"
case 13:
alert('enter pressed');
break;
// "s"
@avireni
avireni / gist:2380745
Created April 13, 2012 23:18
Bind a function to an event
$('#foo').bind('click', function() {
alert('User clicked on "foo."');
});
@avireni
avireni / gist:2380741
Created April 13, 2012 23:17
set an event handler for any element that matches a selector
$('button.someClass').live('click', someFunction);
//Note that in jQuery 1.4.2, the delegate and undelegate options have been
//introduced to replace live as they offer better support for context
//For example, in terms of a table where before you would use..
// .live()
$("table").each(function(){
$("td", this).live("hover", function(){
$(this).toggleClass("hover");
});
@avireni
avireni / gist:2380739
Created April 13, 2012 23:16
Filter using multiple-attributes
var elements = $('#someid input[type=sometype][value=somevalue]').get();
//This precision-based approached can be useful when you use lots of similar input elements which have different types
@avireni
avireni / gist:2380735
Created April 13, 2012 23:15
Verify if an element is empty
if ($('#div').html()) { }
@avireni
avireni / gist:2380731
Created April 13, 2012 23:14
Replace an element with jQuery
$('#div').replaceWith('sample');
@avireni
avireni / gist:2380726
Created April 13, 2012 23:13
Check If An Element contains a certain class or element
//jQuery 1.4.* includes support for the has method. This method will find
//if a an element contains a certain other element class or whatever it is
//you are looking for and do anything you want to them.
$("input").has(".email").addClass("email_icon");
@avireni
avireni / gist:2380724
Created April 13, 2012 23:12
Append HTML to an Element
$('#div').append('text');