/    Sign up×
Community /Pin to ProfileBookmark

How to address ‘this’ ?

How to address ‘this’ ?

Hi all

I have a simple example to illustrate my problem here.

[url]http://www.ttmt.org.uk/this/[/url]

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.

[code]
<script type=”text/javascript”>
$(‘div’).click(function(){
$(this).$(‘p’).html(‘BTN’);
});
</script>
[/code]

[code]
<!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>

[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@aj_nscJan 05.2012 — Read up on the jQuery manual:

<i>
</i>$(this).find('p').html('BTN');
$(this).children('p').html('BTN');
×

Success!

Help @ttmt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...