Solved

hide all div's that start with a certain word

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
jquery 3 and protoype 9 34
JQuery tracking event. 3 39
jquery not selector 4 26
Populating html form in Sharepoint using JSOM 11 26
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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…

706 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