Solved

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

Posted on 2011-02-14
5
654 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
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 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

809 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