Go Premium for a chance to win a PS4. Enter to Win


jQuery: span inside this

Posted on 2011-02-23
Medium Priority
Last Modified: 2012-05-11
How can I access a span inside this?

This does NOT work:
$(this + 'span').html()

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<style type="text/css">
span {
display: none;

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript">
// <![CDATA[

$(document).ready(function() {

	  function () {
		alert($(this + 'span').html() );


// ]]>


<a class="hoverInfo">
One <span>1</span>
<a class="hoverInfo">
Two <span>2</span>
<a class="hoverInfo">
Three <span>3</span>


Open in new window

Question by:hankknight
LVL 43

Accepted Solution

David S. earned 1600 total points
ID: 34964054
You can't concatenate an object with a string like that.

jQuery allows you to specify the context with a second parameter like this:
$('span', this).html()

Open in new window

LVL 15

Assisted Solution

dirknibleck earned 400 total points
ID: 34964060
          function () {
                alert($(this).children('span').html() );

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Suggested Courses

972 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