How to make JQuery event handling work on ajax loaded content?
How to make JQuery event handling work on ajax loaded content?

This code allows us to use JQuery event handling work on ajax loaded content

$('body').on('click','#list-panel .item', function() {
        $('#list-panel .item').removeClass('active');
        $(this).addClass('active');
});


The above code is just an example to remove class "active" from other items and add it to the currently clicked element.

Related Questions

jQuery click not working in AJAX loaded content.
jQuery click() event not firing on AJAX loaded HTML elements
jquery click doesnt work on ajax generated content
jQuery not working in AJAX Loaded page
Jquery click function doesn't work after ajax call?
jQuery click() event not firing on AJAX loaded HTML elements
jQuery code doesn’t work on dynamic content loaded with ajax


How to make JQuery event handling work on ajax loaded content?

on September 11, 2014
How to make JQuery event handling work on ajax loaded content?
How to make JQuery event handling work on ajax loaded content?

This code allows us to use JQuery event handling work on ajax loaded content

$('body').on('click','#list-panel .item', function() {
        $('#list-panel .item').removeClass('active');
        $(this).addClass('active');
});


The above code is just an example to remove class "active" from other items and add it to the currently clicked element.

Related Questions

jQuery click not working in AJAX loaded content.
jQuery click() event not firing on AJAX loaded HTML elements
jquery click doesnt work on ajax generated content
jQuery not working in AJAX Loaded page
Jquery click function doesn't work after ajax call?
jQuery click() event not firing on AJAX loaded HTML elements
jQuery code doesn’t work on dynamic content loaded with ajax


If you add a class vertical to your carousel, then adding the following CSS to the page will override the sliding to be vertical:


.vertical .carousel-inner {
  height: 100%;
}
.carousel.vertical .item {
  -webkit-transition: 0.6s ease-in-out top;
     -moz-transition: 0.6s ease-in-out top;
      -ms-transition: 0.6s ease-in-out top;
       -o-transition: 0.6s ease-in-out top;
          transition: 0.6s ease-in-out top;
}

.carousel.vertical .active {
  top: 0;
}

.carousel.vertical .next {
  top: 100%;
}

.carousel.vertical .prev {
  top: -100%;
}

.carousel.vertical .next.left,
.carousel.vertical .prev.right {
  top: 0;
}

.carousel.vertical .active.left {
  top: -100%;
}

.carousel.vertical .active.right {
  top: 100%;
}

.carousel.vertical .item {
    left: 0;
}​

Twitter Bootstrap carousel vertical sliding

on September 10, 2014
If you add a class vertical to your carousel, then adding the following CSS to the page will override the sliding to be vertical:


.vertical .carousel-inner {
  height: 100%;
}
.carousel.vertical .item {
  -webkit-transition: 0.6s ease-in-out top;
     -moz-transition: 0.6s ease-in-out top;
      -ms-transition: 0.6s ease-in-out top;
       -o-transition: 0.6s ease-in-out top;
          transition: 0.6s ease-in-out top;
}

.carousel.vertical .active {
  top: 0;
}

.carousel.vertical .next {
  top: 100%;
}

.carousel.vertical .prev {
  top: -100%;
}

.carousel.vertical .next.left,
.carousel.vertical .prev.right {
  top: 0;
}

.carousel.vertical .active.left {
  top: -100%;
}

.carousel.vertical .active.right {
  top: 100%;
}

.carousel.vertical .item {
    left: 0;
}​

So here's what we are gonna do...

We're going to use "responsive design" principles (CSS @media queries) to detect if the screen is smaller than the maximum squishitude of our table. If it is, we're going to reformat the table.
We're being good little developers and using Plain Ol' Semantic Markup here for our table. Bare bones example:
<table>
 <thead>
 <tr>
  <th>First Name</th>
  <th>Last Name</th>
  <th>Job Title</th>
 </tr>
 </thead>
 <tbody>
 <tr>
  <td>James</td>
  <td>Matman</td>
  <td>Chief Sandwich Eater</td>
 </tr>
 <tr>
  <td>The</td>
  <td>Tick</td>
  <td>Crimefighter Sorta</td>
 </tr>
 </tbody>
</table>
Our regular CSS is nothing special:
/* 
Generic Styling, for Desktops/Laptops 
*/
table { 
  width: 100%; 
  border-collapse: collapse; 
}
/* Zebra striping */
tr:nth-of-type(odd) { 
  background: #eee; 
}
th { 
  background: #333; 
  color: white; 
  font-weight: bold; 
}
td, th { 
  padding: 6px; 
  border: 1px solid #ccc; 
  text-align: left; 
}
The small-screen responsive stuff comes in now. We've already figured out our minimum table width is about 760px so we'll set up our media query to take effect when the narrower than that. Also, we'll target iPads as they are right in that zone.
The biggest change is that we are going to force the table to not behave like a table by setting every table-related element to be block-level. Then by keeping the zebra striping we originally added, it's kind of like each table row becomes a table in itself, but only as wide as the screen. No more horizontal scrolling! Then for each "cell", we'll use CSS generated content (:before) to apply the label, so we know what each bit of data means.
/* 
Max width before this PARTICULAR table gets nasty
This query will take effect for any screen smaller than 760px
and also iPads specifically.
*/
@media 
only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px)  {

 /* Force table to not be like tables anymore */
 table, thead, tbody, th, td, tr { 
  display: block; 
 }
 
 /* Hide table headers (but not display: none;, for accessibility) */
 thead tr { 
  position: absolute;
  top: -9999px;
  left: -9999px;
 }
 
 tr { border: 1px solid #ccc; }
 
 td { 
  /* Behave  like a "row" */
  border: none;
  border-bottom: 1px solid #eee; 
  position: relative;
  padding-left: 50%; 
 }
 
 td:before { 
  /* Now like a table header */
  position: absolute;
  /* Top/left values mimic padding */
  top: 6px;
  left: 6px;
  width: 45%; 
  padding-right: 10px; 
  white-space: nowrap;
 }
 
 /*
 Label the data
 */
 td:nth-of-type(1):before { content: "First Name"; }
 td:nth-of-type(2):before { content: "Last Name"; }
 td:nth-of-type(3):before { content: "Job Title"; }
 td:nth-of-type(4):before { content: "Favorite Color"; }
 td:nth-of-type(5):before { content: "Wars of Trek?"; }
 td:nth-of-type(6):before { content: "Porn Name"; }
 td:nth-of-type(7):before { content: "Date of Birth"; }
 td:nth-of-type(8):before { content: "Dream Vacation City"; }
 td:nth-of-type(9):before { content: "GPA"; }
 td:nth-of-type(10):before { content: "Arbitrary Data"; }
}
And so, desktops get the regular table experience, mobile (or otherwise small screens) get a reformatted and easier to explore table:

Hey what about IE?

IE 9 and down don't like you setting table elements as display: block; It does weird stuff and doesn't work right. But IE 9 does support media queries. So my solution thus far is just to wrap the media query styles in conditional comments.
<!--[if !IE]><!-->
<style>
   /* table-related media query stuff only */
</style>
/* Or an external stylesheet or whatever */
<!--<![endif]-->
If the problem was only that older versions of IE don't support media queries, we could use the css3-mediaqueries-js project (polyfills support for all media queries) orRespond (also polyfill, way smaller, but only does min/max-width). They both work very well. But this isn't our problem in this case.
This all works fine in IE 10 and IE 10 also ignores conditional comments, so the styles will work even if wrapped in !IE conditionals.

How to make a responsive table

on September 09, 2014

So here's what we are gonna do...

We're going to use "responsive design" principles (CSS @media queries) to detect if the screen is smaller than the maximum squishitude of our table. If it is, we're going to reformat the table.
We're being good little developers and using Plain Ol' Semantic Markup here for our table. Bare bones example:
<table>
 <thead>
 <tr>
  <th>First Name</th>
  <th>Last Name</th>
  <th>Job Title</th>
 </tr>
 </thead>
 <tbody>
 <tr>
  <td>James</td>
  <td>Matman</td>
  <td>Chief Sandwich Eater</td>
 </tr>
 <tr>
  <td>The</td>
  <td>Tick</td>
  <td>Crimefighter Sorta</td>
 </tr>
 </tbody>
</table>
Our regular CSS is nothing special:
/* 
Generic Styling, for Desktops/Laptops 
*/
table { 
  width: 100%; 
  border-collapse: collapse; 
}
/* Zebra striping */
tr:nth-of-type(odd) { 
  background: #eee; 
}
th { 
  background: #333; 
  color: white; 
  font-weight: bold; 
}
td, th { 
  padding: 6px; 
  border: 1px solid #ccc; 
  text-align: left; 
}
The small-screen responsive stuff comes in now. We've already figured out our minimum table width is about 760px so we'll set up our media query to take effect when the narrower than that. Also, we'll target iPads as they are right in that zone.
The biggest change is that we are going to force the table to not behave like a table by setting every table-related element to be block-level. Then by keeping the zebra striping we originally added, it's kind of like each table row becomes a table in itself, but only as wide as the screen. No more horizontal scrolling! Then for each "cell", we'll use CSS generated content (:before) to apply the label, so we know what each bit of data means.
/* 
Max width before this PARTICULAR table gets nasty
This query will take effect for any screen smaller than 760px
and also iPads specifically.
*/
@media 
only screen and (max-width: 760px),
(min-device-width: 768px) and (max-device-width: 1024px)  {

 /* Force table to not be like tables anymore */
 table, thead, tbody, th, td, tr { 
  display: block; 
 }
 
 /* Hide table headers (but not display: none;, for accessibility) */
 thead tr { 
  position: absolute;
  top: -9999px;
  left: -9999px;
 }
 
 tr { border: 1px solid #ccc; }
 
 td { 
  /* Behave  like a "row" */
  border: none;
  border-bottom: 1px solid #eee; 
  position: relative;
  padding-left: 50%; 
 }
 
 td:before { 
  /* Now like a table header */
  position: absolute;
  /* Top/left values mimic padding */
  top: 6px;
  left: 6px;
  width: 45%; 
  padding-right: 10px; 
  white-space: nowrap;
 }
 
 /*
 Label the data
 */
 td:nth-of-type(1):before { content: "First Name"; }
 td:nth-of-type(2):before { content: "Last Name"; }
 td:nth-of-type(3):before { content: "Job Title"; }
 td:nth-of-type(4):before { content: "Favorite Color"; }
 td:nth-of-type(5):before { content: "Wars of Trek?"; }
 td:nth-of-type(6):before { content: "Porn Name"; }
 td:nth-of-type(7):before { content: "Date of Birth"; }
 td:nth-of-type(8):before { content: "Dream Vacation City"; }
 td:nth-of-type(9):before { content: "GPA"; }
 td:nth-of-type(10):before { content: "Arbitrary Data"; }
}
And so, desktops get the regular table experience, mobile (or otherwise small screens) get a reformatted and easier to explore table:

Hey what about IE?

IE 9 and down don't like you setting table elements as display: block; It does weird stuff and doesn't work right. But IE 9 does support media queries. So my solution thus far is just to wrap the media query styles in conditional comments.
<!--[if !IE]><!-->
<style>
   /* table-related media query stuff only */
</style>
/* Or an external stylesheet or whatever */
<!--<![endif]-->
If the problem was only that older versions of IE don't support media queries, we could use the css3-mediaqueries-js project (polyfills support for all media queries) orRespond (also polyfill, way smaller, but only does min/max-width). They both work very well. But this isn't our problem in this case.
This all works fine in IE 10 and IE 10 also ignores conditional comments, so the styles will work even if wrapped in !IE conditionals.

See the Pen set (JS options) by Joshua Rudd (@joshuarudd) on CodePen.

How to add the UserVoice widget to your site

on September 03, 2014

See the Pen set (JS options) by Joshua Rudd (@joshuarudd) on CodePen.

Creating A Pure CSS Star Rating Selection


A star rating system built with pure CSS. This can obviously be done with JavaScript, and for now it’s probably the better option for browser support, but hey, I had fun making it.

The functionality is achieved with radio buttons, and using the CSS :checked selector to decide how many stars are on show. This will look something like.
1
input[value="5"]:checked + .rating-fill{ /* some css */  }
This line of CSS says that, when the input with a value of 5 is checked, then apply whatever style to the element with a class of .rating-fill. The “+” selector means only apply the style to the element that appears directly after it.

First off let’s setup the HTML.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<div class="rating-wrap">
    <div class="radio-wrap">
        <input type="radio" name="rating" value="1"></input>
        <div class="rating-fill"></div>
        <input type="radio" name="rating" value="2"></input>
        <div class="rating-fill"></div>
        <input type="radio" name="rating" value="3"></input>
        <div class="rating-fill"></div>
        <input type="radio" name="rating" value="4"></input>
        <div class="rating-fill"></div>
        <input type="radio" name="rating" value="5"></input>
        <div class="rating-fill"></div>
    </div>
    <div class="rating-blank"></div>
</div>
Each radio button has a different value, and this is the key aspect that allows us to apply a different style (in our case the width) to each proceeding .rating-fill.
Near the bottom is an element with the class “rating-empty”. This will show the stars in a grayed out state. Then with CSS we will position all of these elements on top of each other, to achieve the desired effect.

The CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
body{
    background:#23252b;
}
/* Wrappers */
.rating-wrap{
    width:150px;
    height:25px;
    position:relative;
}
.radio-wrap{
    width:100%;
    height:100%;
}
/* Radio Buttons */
input[type=radio] {
    display:inline-block;
    position:relative;
    z-index:2;
    margin:0;
    width:17.4%;
    height:100%;
    opacity:0;
}
/* Filled Rating */
.rating-fill{
    width:0;
    height:100%;
    background:url(star.png) #efaf16;
    position:absolute;
    top:0;
    left:0;
    z-index:1;
}
/* Checked Inputs */
input[value="5"]:checked + .rating-fill{
    width:100%;
}
input[value="4"]:checked + .rating-fill{
    width:80%;
}
input[value="3"]:checked + .rating-fill{
    width:60%;
}
input[value="2"]:checked + .rating-fill{
    width:40%;
}
input[value="1"]:checked + .rating-fill{
    width:20%;
}
/* Blank Stars */
.rating-blank{
    width:100%;
    height:100%;
    background:url(star.png) #ccc;
    position:absolute;
    top:0;
    left:0;
    z-index:0;
}

Creating A Pure CSS Star Rating Selection

on August 29, 2014

Creating A Pure CSS Star Rating Selection


A star rating system built with pure CSS. This can obviously be done with JavaScript, and for now it’s probably the better option for browser support, but hey, I had fun making it.

The functionality is achieved with radio buttons, and using the CSS :checked selector to decide how many stars are on show. This will look something like.
1
input[value="5"]:checked + .rating-fill{ /* some css */  }
This line of CSS says that, when the input with a value of 5 is checked, then apply whatever style to the element with a class of .rating-fill. The “+” selector means only apply the style to the element that appears directly after it.

First off let’s setup the HTML.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<div class="rating-wrap">
    <div class="radio-wrap">
        <input type="radio" name="rating" value="1"></input>
        <div class="rating-fill"></div>
        <input type="radio" name="rating" value="2"></input>
        <div class="rating-fill"></div>
        <input type="radio" name="rating" value="3"></input>
        <div class="rating-fill"></div>
        <input type="radio" name="rating" value="4"></input>
        <div class="rating-fill"></div>
        <input type="radio" name="rating" value="5"></input>
        <div class="rating-fill"></div>
    </div>
    <div class="rating-blank"></div>
</div>
Each radio button has a different value, and this is the key aspect that allows us to apply a different style (in our case the width) to each proceeding .rating-fill.
Near the bottom is an element with the class “rating-empty”. This will show the stars in a grayed out state. Then with CSS we will position all of these elements on top of each other, to achieve the desired effect.

The CSS

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
body{
    background:#23252b;
}
/* Wrappers */
.rating-wrap{
    width:150px;
    height:25px;
    position:relative;
}
.radio-wrap{
    width:100%;
    height:100%;
}
/* Radio Buttons */
input[type=radio] {
    display:inline-block;
    position:relative;
    z-index:2;
    margin:0;
    width:17.4%;
    height:100%;
    opacity:0;
}