Jquery select id ending with wildcard

Hi,

I have the following line:

$(".myclass #my_div_3").css('display', 'visible').html("my html text here");

Is it possible to change the _3 to a wild card so the .css() and .html() will apply to any number?

I guess something like #my_div_*

What would be the best way to do this?

Thanks!

To get elements that begin with “my_div_”:

$(“[id^=my_div_]”)

Thanks.

I think I worded my question badly. This is what I would like to achieve:

I have the following divs on my page:


<div id="my_id_1>content></div>
<div id="my_id_2>different content></div>
<div id="my_id_3></div>
<div id="my_id_4>more content></div>
<div id="my_id_5></div>

What I want to do is add a class/ insert content to the my_id_3 and any other divs that are empty.

What would be the best way to do this?

Thanks!

Found this on another site:

$(‘div’).each(function(){
if(!/[\S]/.test($(this).html())) {
// code to execute for empty divs
}
})

Thanks, I got it to work, but only in Firebug. When I place it in my code, it doesn’t work. I’ve tried adding it to the head, before the closing body tag but it doesn’t work.

Do you know what would cause this?

Thanks

First thing - is it within document ready?

Second thing - wipe the cache of all browsers and try, again. I hate that IE defaults to “cache everything”. As a developer, the first thing I do is change it to “with every page load”. And I use CTRL-F5 to refresh, every time.

Third thing - I’m teasing… there is no third thing. :slight_smile:

Hi,

Yep its in document.ready and I’ve cleared my cache and it still doesn’t show :confused:

Hmm… put it in a try/catch, parse the message, and alert it. Something like…


try{
  // js code
}catch(e){
  var msg = "";
  for(var x in e){ msg += x + ": " + e[x] + "\
";}
  alert(msg);
}