Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do I select the h3 tag inside a div? (prototype.js)

Posted on 2011-02-14
5
Medium Priority
?
672 Views
Last Modified: 2012-05-11
<div id="indivpost1">
	<img src="th-1.jpg" />
	<h3></h3>
</div>

Open in new window


Shouldn't this work?
$$('#indivpost1 h3')

Open in new window


Please tell me what I'm doing wrong.
0
Comment
Question by:ram0nm
[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
5 Comments
 
LVL 9

Expert Comment

by:CCSOFlag
ID: 34890970
your tag says javascript, but it looks like you are looking for JQuery maybe?

I don't use JQuery, but in Javascript it is:

var myDiv = document.getElementById('indivpost1');
var myTag = myDiv.getElementsByTagName('h3');


This will get you all h3 tags within that element.
0
 

Author Comment

by:ram0nm
ID: 34890991
Thanks for your help but I'm using Prototype not jQuery.
0
 
LVL 3

Expert Comment

by:JuanchoVzla
ID: 34891216
>>$$('#indivpost1 h3')
This should return an array with one element (with your example)
0
 
LVL 3

Expert Comment

by:JuanchoVzla
ID: 34891236
try breaking it down
$$('#indivpost1') .find('h3');
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 34903878
To get the first one : $$("#indivpost1 h3").first();

Test page :


<!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>Untitled Document</title>
<script language="javascript" src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js"></script>
<script language="javascript">
	Event.observe(window, 'load', function() {
		alert( $$("#indivpost1 h3").first().innerHTML );
	});
</script>
</head>
<body>
<div id="indivpost1">
	<img src="http://www.codersadvocate.com/images/1245141859.gif" />
	<h3>First</h3>
	<h3>Second</h3>
</div>
</body>
</html>

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

618 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