Solved

hide all div's that start with a certain word

Posted on 2011-03-10
2
676 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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…

785 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