Solved

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

689 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