Solved

hide all div's that start with a certain word

Posted on 2011-03-10
2
681 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
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…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

688 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