Quick question. If i am trying to clear multiple divs with the same class all at once is there a jQuery short cut to doing this? I tried $('.clearit').empty();
and that does not seem to work at all (none on the divs with that class are being cleared). Could I be doing this wrong or does this just not work? Let me know, I tried $('.clearit').html('');
. Also I have this along with other code that runs after it in jquery and everything else runs as it should. I debugged the code and it seems to run the function and move on with no errors but the div content is not cleared. Here is a sample of the divs:
<center><div class="clearit" id="container2">Loading the player ...</div></center>
</li>
<li>
<center><div class="clearit" id="container3">Loading the player ...</div></center>
</li>
<li>
<center><div class="clearit" id="container4">Loading the player ...</div></center>
and here is the code for one of the handlers. Please note everything in there works except for the $('.clearit').html('');
.
$('.thumbNav li a').click(function(){
$('.clearit').html('');
var str = $(this).html();
var pattern = /[0-9]+/g;
var matches = str.match(pattern);
var myInteger = parseInt(matches);
//variable for player
var container = "container"+myInteger;
var what = 'skill'+myInteger;
var location = "https://aliahealthcare.com/videofetcher.php?id=skill"+myInteger;
player(container,what,location);
$('#'+what).attr('selected', 'selected');
});
To anyone still helping me, THANKS SO MUCH! also i have modified the site so you no longer need a login to get in so you can see it in action for yourself. Please use the code above as reference in finding the javascript. (It is all located in vid.php) Thanks
https://aliahealthcare.com/vid.php
Also i just discovered something interesting. The li's above are part of a ul with in id of slider. When i do $('#slider').html('');
or $('#slider').empty();
It works but it clears all the div thus the players that load inside those divs dont load. All i need to do is just clear the players so you cant have multipul players running at the same time.
Please see working demo here: http://jsfiddle.net/TxR8K/
updated from your given code: http://jsfiddle.net/TxR8K/1/
by the way your unordered list tag i.e. ul
is missing in the sample :)
Update further after discussion with OP - we also found out - the player is actually not part of the html in the div, hence he/she knows what needs to be done and clears his./her way for further fix :)
This should do the trick
$('.clearit').html('');
Your problem is most likely that you're running that command before the DOM has loaded. Open a console window in StackOverflow and run $("div").empty();
. Everything disappears!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With