How to address 'this'?

How to address ‘this’ ?

Hi all

I have a simple example to illustrate my problem here.

http://www.ttmt.org.uk/this/

I have a group of div’s with a <p> tag inside.

When I click the div I want to place text in the <p> of that button.

How do I address the <p> of this div being clicked.

I tried this.


<script type="text/javascript">
  $('div').click(function(){
    $(this).$('p').html('BTN');
  });
</script>


<!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" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

	<title>untitled</title>

	<style type="text/css" media="screen">
	 *{
	   margin:0;
	   padding:0;
	 }
	 div.btn{
	   background:red;
	   cursor:pointer;
	   height:100px;
	   margin:50px;
	   width:200px;
	 }
	</style>
</head>

<body>

  <div class="btn">
    <p></p>
  </div>

  <div class="btn">
    <p></p>
  </div>

  <div class="btn">
    <p></p>
  </div>

  <div class="btn">
    <p></p>
  </div>

  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>

  <script type="text/javascript">
    $('div').click(function(){
      $(this).$('p').html('BTN');
    });
  </script>
	
</body>
</html>


I’n no expert, but isn’t it something like
$(this).children(‘p’)
to access the p descendants of $this ?

You use the p selector from within the context of the this element. See http://api.jquery.com/jQuery/#jQuery1


$('p', this).html('BTN');