jQuery: inside an element

0 Sampan Verma · May 16, 2015
First of all thanks for helping.

I have selected an element suppose div. The div contains other span elements. Through the div i want to select the spans inside it. How should fo it?

by through the div i mean using the select div in $ to find the child span.

Post a Reply

Replies

Oldest  Newest  Rating
0 Azim Udin · May 16, 2015
i am not entirely sure what you are looking for....

you can use
$('div > span').SomeMethod();
or may be...
$('div').children('span').SomeMethod();

this might help


https://api.jquery.com/children/
https://api.jquery.com/child-selector/
0 Sampan Verma · May 17, 2015
Thanks for help but thats not what im looking for.

$('elem').click(function(){

})
0 Sampan Verma · May 17, 2015
Thanks for help but thats not what im looking for.

$('elem').click(function(){

})
0 Sampan Verma · May 17, 2015
$('elem').click(function(){
$(this).???().??();
})



??? is how to select a span elem inside this element any cool function name.

?? is how to get its html content
0 Sampan Verma · May 17, 2015
So I need a answer. Thanks for replying
0 Abdullah Nauman · May 18, 2015
Why is this never used? 

https://www.thenewboston.com/forum/category.php?id=175
0 Superman HC · May 18, 2015
If i get what's you are looking,, you are asking how to get some function performed on an element that is a child of a div...
If yes.. then look for the code below.. i have created a simple code for counting the elements: 

/*HTML CODE */
<html>
<head>
</head>
<body>
<div id="ref">
<span>
<p>blahblah</p>
<h2>More blahblah</h2>
</span>
</div>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="demo.js"></script>

</body>
</html>

/* JS CODE */

var z = $('#ref span').find('*').length;

alert(z);
0 Ali Hassan · May 18, 2015
hmmm

$('elem').click(function(){
// if you are trying to select a certain span

})
0 Sampan Verma · May 18, 2015
Thanks Everyone again.

Keylor Renslow got this right.

Ravi Ahuja, I tried to that one but believe me its is just a pain in the butt.
  • 1

Javascript

107,196 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators