Styling Bootstrap-tables after AJAX
up vote
1
down vote
favorite
I'm working on a site built in WordPress/WooCommerce. I didn't ask this question on the WordPress-StackExchange since the question isn't about the WordPress-/WooCommerce-part.
On the site, there are a few <table>
's, that needed styling. So I added this jQuery-snippet, to add the .table
-class to all the tables (found here).
jQuery(document).ready(function(){
// Make all tables into Bootstrap-tables
jQuery( 'main' ).find( 'table' ).each( function() {
jQuery( this ).addClass( 'table' );
}
);
});
However... On one of the pages (the cart), there is an AJAX-request that updates the cart. And when it returns the new information, then the table no longer has the class (or the stylings).
I would hate to style that table manually, when everthing is 'right there', delivered from Bootstrap.
I considered these two options:
- A) Add something to my script, that checks for AJAX-request or something like that? And if so, - how do I do that?
or
- B) Do something, so the Bootstrap-styles applied to all
<table>
-elements (and not just<table class='table'>
-elements? And if so, - how do I do that? Changing bootstrap.min.css seem like a bad idea.
They both seem hacky/clumbsy. Am I missing a better way of doing this?
jquery css bootstrap-4
add a comment |
up vote
1
down vote
favorite
I'm working on a site built in WordPress/WooCommerce. I didn't ask this question on the WordPress-StackExchange since the question isn't about the WordPress-/WooCommerce-part.
On the site, there are a few <table>
's, that needed styling. So I added this jQuery-snippet, to add the .table
-class to all the tables (found here).
jQuery(document).ready(function(){
// Make all tables into Bootstrap-tables
jQuery( 'main' ).find( 'table' ).each( function() {
jQuery( this ).addClass( 'table' );
}
);
});
However... On one of the pages (the cart), there is an AJAX-request that updates the cart. And when it returns the new information, then the table no longer has the class (or the stylings).
I would hate to style that table manually, when everthing is 'right there', delivered from Bootstrap.
I considered these two options:
- A) Add something to my script, that checks for AJAX-request or something like that? And if so, - how do I do that?
or
- B) Do something, so the Bootstrap-styles applied to all
<table>
-elements (and not just<table class='table'>
-elements? And if so, - how do I do that? Changing bootstrap.min.css seem like a bad idea.
They both seem hacky/clumbsy. Am I missing a better way of doing this?
jquery css bootstrap-4
1
"main"
is class or tag?
– DPS
Nov 11 at 7:38
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm working on a site built in WordPress/WooCommerce. I didn't ask this question on the WordPress-StackExchange since the question isn't about the WordPress-/WooCommerce-part.
On the site, there are a few <table>
's, that needed styling. So I added this jQuery-snippet, to add the .table
-class to all the tables (found here).
jQuery(document).ready(function(){
// Make all tables into Bootstrap-tables
jQuery( 'main' ).find( 'table' ).each( function() {
jQuery( this ).addClass( 'table' );
}
);
});
However... On one of the pages (the cart), there is an AJAX-request that updates the cart. And when it returns the new information, then the table no longer has the class (or the stylings).
I would hate to style that table manually, when everthing is 'right there', delivered from Bootstrap.
I considered these two options:
- A) Add something to my script, that checks for AJAX-request or something like that? And if so, - how do I do that?
or
- B) Do something, so the Bootstrap-styles applied to all
<table>
-elements (and not just<table class='table'>
-elements? And if so, - how do I do that? Changing bootstrap.min.css seem like a bad idea.
They both seem hacky/clumbsy. Am I missing a better way of doing this?
jquery css bootstrap-4
I'm working on a site built in WordPress/WooCommerce. I didn't ask this question on the WordPress-StackExchange since the question isn't about the WordPress-/WooCommerce-part.
On the site, there are a few <table>
's, that needed styling. So I added this jQuery-snippet, to add the .table
-class to all the tables (found here).
jQuery(document).ready(function(){
// Make all tables into Bootstrap-tables
jQuery( 'main' ).find( 'table' ).each( function() {
jQuery( this ).addClass( 'table' );
}
);
});
However... On one of the pages (the cart), there is an AJAX-request that updates the cart. And when it returns the new information, then the table no longer has the class (or the stylings).
I would hate to style that table manually, when everthing is 'right there', delivered from Bootstrap.
I considered these two options:
- A) Add something to my script, that checks for AJAX-request or something like that? And if so, - how do I do that?
or
- B) Do something, so the Bootstrap-styles applied to all
<table>
-elements (and not just<table class='table'>
-elements? And if so, - how do I do that? Changing bootstrap.min.css seem like a bad idea.
They both seem hacky/clumbsy. Am I missing a better way of doing this?
jquery css bootstrap-4
jquery css bootstrap-4
asked Nov 11 at 7:19
Zeth
53811131
53811131
1
"main"
is class or tag?
– DPS
Nov 11 at 7:38
add a comment |
1
"main"
is class or tag?
– DPS
Nov 11 at 7:38
1
1
"main"
is class or tag?– DPS
Nov 11 at 7:38
"main"
is class or tag?– DPS
Nov 11 at 7:38
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
you can use ajaxComplete
this work when every ajax request completes.
$( document ).ajaxComplete(function( event, xhr, settings ) {
$("table").addClass("table");
});
Awesome! This works.
– Zeth
Nov 11 at 8:05
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
you can use ajaxComplete
this work when every ajax request completes.
$( document ).ajaxComplete(function( event, xhr, settings ) {
$("table").addClass("table");
});
Awesome! This works.
– Zeth
Nov 11 at 8:05
add a comment |
up vote
2
down vote
accepted
you can use ajaxComplete
this work when every ajax request completes.
$( document ).ajaxComplete(function( event, xhr, settings ) {
$("table").addClass("table");
});
Awesome! This works.
– Zeth
Nov 11 at 8:05
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
you can use ajaxComplete
this work when every ajax request completes.
$( document ).ajaxComplete(function( event, xhr, settings ) {
$("table").addClass("table");
});
you can use ajaxComplete
this work when every ajax request completes.
$( document ).ajaxComplete(function( event, xhr, settings ) {
$("table").addClass("table");
});
answered Nov 11 at 7:35
mahradbt
1369
1369
Awesome! This works.
– Zeth
Nov 11 at 8:05
add a comment |
Awesome! This works.
– Zeth
Nov 11 at 8:05
Awesome! This works.
– Zeth
Nov 11 at 8:05
Awesome! This works.
– Zeth
Nov 11 at 8:05
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246645%2fstyling-bootstrap-tables-after-ajax%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
"main"
is class or tag?– DPS
Nov 11 at 7:38