954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How do you select all id divs that contain a certain string in jquery?

hi,
i need to empty all the divs whic has an id like 'bkoption'
eg : my html code is like this

<div class="subsubsubmenu" id="bkoption1">some content</div>
<div class="subsubsubmenu" id="bkoption2">some content</div>
<div class="subsubsubmenu" id="bkoption3">some content</div>

so when i trigger an on click function i need to empty all of these divs.
i wrote something like this to test before coding the rest, which didn't work , or even didn't show an error on firebug.

$('div[id*="bkoption"]').each(function(index) {
	alert(index + ': ' + $(this).text());
});

what am i doing wrong?
much appreciate reply.

Virangya
Junior Poster
122 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

If you plan to learn scripting any time soon, you should first forget about its wrappers.

var divstoclear = document.getElementsByClassName("subsubmenu"),x;
for(x in divstoclear){divstoclear[x].innerHTML="";

* using innerHTML property here because you don't want empty elements pilling.

Troy III
Practically a Master Poster
609 posts since Jun 2008
Reputation Points: 120
Solved Threads: 80
 

thank you for ur reply.
wrappers? u mean id here..? please forget about the class name here... its irrelavent. i should have removed it from the code, please forget there is a class at all.
i only want to select div which has an id like 'bkoption'

<div id="bkoption1">some content</div>
<div id="bkoption2">some content</div>
<div id="bkoption3">some content</div>
Virangya
Junior Poster
122 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

hi, my function actually worked... it turn out to be that my browser has cashed data. lately my firefox is cashing too frequently. i don't know why and it's like i have to clear cashe very hour or more when i'm developing :-/

Virangya
Junior Poster
122 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: