Solved

hide all div's that start with a certain word

Posted on 2011-03-10
2
675 Views
Last Modified: 2012-05-11
Hi,

I have a few divs

<div id="help_a">a</div>
<div id="help_b">b</div>
<div id="help_c">c</div>
<div id="help_d">d</div>

When the page loads I have a function that is supposed to hide all of them (but doesn't work):

$(function() {
  $("div[id^='help_']").each(function() {
      this.id.hide();
  });
});

What am I doing wrong?

Thanks!
0
Comment
Question by:jagku
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 35096183
replace
this.id.hide();

Open in new window

by
$(this).hide()

Open in new window


work for me :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script language="javascript" src="http://code.jquery.com/jquery-1.5.1.min.js"></script>
<script language="javascript">

	$(document).ready(function() {
	  $("div[id^='help_']").each(function() {
	      $(this).hide();
	  });
  });

</script>
<body>
<div id="help_a">a</div>
<div id="help_b">b</div>
<div id="help_c">c</div>
<div id="help_d">d</div>
<div id="ahelp_d">not me</div>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:jagku
ID: 35096276
doh!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now