|
Page 1 of 1 |
|
Posted: Sat, 14th Jun 2014 23:54 Post subject: jQuery hiding an element |
|
 |
So I have a div, that is filled with content on one page, but is empty on the other page, but because I'm working in Joomla, I had to manually add that div in the index.php file, which means that when I remove the content on other pages I'm left with this empty div.
So I'm looking for a way to remove, hide or whatever, but I tried it and it's not working. I don't get any errors, but my div is still there. I tried with
Code: |
(function ($) {
$('.blue_yjsg5_out').each(function(){
if ($(this).find('.blue_yjsg5_out').is(':empty')){
$('.blue_yjsg5_out').css('display:none');
}
});
}(jQuery)); |
But nothing happens.
I also tried
Code: |
(function ($) {
$('.blue_yjsg5_out:empty').hide();
}(jQuery)); |
Nothing. Also
Code: |
(function ($) {
$('.blue_yjsg5_out:empty').css('display:none');
}(jQuery)); |
Nada.
This
Code: | (function ($) {
$(document).ready(function () {
$('.blue_yjsg5_out:empty').hide();
});
}(jQuery)); |
Zilch.
So I must be doing something wrong.
"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson chiv wrote: | thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found. |
|
|
Back to top |
|
 |
|
Posted: Sun, 15th Jun 2014 00:49 Post subject: |
|
 |
Last edited by Interinactive on Tue, 5th Oct 2021 02:03; edited 1 time in total
|
|
Back to top |
|
 |
|
Posted: Sun, 15th Jun 2014 01:05 Post subject: |
|
 |
Interinactive wrote: | $(".whatever").hide();
Should do it. Wrap it in whatever load/ready function works for you
If you want to hide it on a page by page basis, add body classes and put that before .whatever
Also, why not use body classes and display:none? Unless I'm misunderstanding your question either of those should work
Joomla is garbage too, if I were you I'd get into WP instead |
At monday I'm starting work in WP so I'll get some practice there
The thing is, the div with class 'blue_yjsg5_out' is something I put there, it's always there, and Joomla doesn't have pages per se. Joomla uses menus, modules and articles as it's building block. So my <div class="blue_yjsg5_out"> has on my first 'page' other divs inside it, but on my second page (because I turned the other stuff off, so that they don't show on that page) it's empty.
Now the issue is that that class has a background image in it, so while on my first page that makes sense, it doesn't on my second page.
My front page looks something like this:
My second looks like this
There is no content so it's not needed, but the div isn't hidden so I need a way to hide it...
"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson chiv wrote: | thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found. |
|
|
Back to top |
|
 |
|
Posted: Sun, 15th Jun 2014 01:11 Post subject: |
|
 |
why do you care hiding a div that has no content and isn't visible after all? Provide some links dude 
|
|
Back to top |
|
 |
|
Posted: Sun, 15th Jun 2014 08:42 Post subject: |
|
 |
PumpAction wrote: | why do you care hiding a div that has no content and isn't visible after all? Provide some links dude  |
The problem is the div is visible xD See the picture in the background of the book? I want that gone
I'll PM you the website 
"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson chiv wrote: | thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found. |
|
|
Back to top |
|
 |
|
Posted: Sun, 15th Jun 2014 15:53 Post subject: |
|
 |
No one? :\
"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson chiv wrote: | thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found. |
|
|
Back to top |
|
 |
|
Posted: Sun, 15th Jun 2014 17:55 Post subject: |
|
 |
Found it!
Code: |
<script>
jQuery.noConflict();
(function ($) {
$(document).ready(function(){
$(window).load(function() {
$('.blue_yjsg5_out').filter(function() {
return $.trim($(this).text()) === ''
}).hide()
});
});
}(jQuery));
</script>
|
"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson chiv wrote: | thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found. |
|
|
Back to top |
|
 |
|
Posted: Sun, 15th Jun 2014 18:55 Post subject: |
|
 |
dingo_d wrote: | Code: |
$(document).ready(function(){
$(window).load(function() {
|
|
there's a danger of a race condition here where .load might never run
would it work to just use .load()?
though, it should work fine with just .ready()
are the divs filled/created with a script on page load?
if yes, then there's always a race condition with that script
if you know the div will be empty, you could just skip javascript all together and just have
Code: |
<style>
.blue_yjsg5_out:empty {
display:none;
}
</style>
|
|
|
Back to top |
|
 |
|
Posted: Sun, 15th Jun 2014 21:05 Post subject: |
|
 |
shole wrote: | dingo_d wrote: | [code:1]
$(document).ready(function(){
$(window).load(function() {
[/code:1] |
there's a danger of a race condition here where .load might never run
would it work to just use .load()?
though, it should work fine with just .ready()
are the divs filled/created with a script on page load?
if yes, then there's always a race condition with that script
if you know the div will be empty, you could just skip javascript all together and just have
[code:1]
<style>
.blue_yjsg5_out:empty {
display:none;
}
</style>
[/code:1] |
The thing is, the divs must load first, because on one page they are filled with content, and on the other they are not.
Style thing is out of the question because I need it to look a certain way on the first page.
"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson chiv wrote: | thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found. |
|
|
Back to top |
|
 |
Page 1 of 1 |
All times are GMT + 1 Hour |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group
|
|
 |
|