Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
<td class="fc-day fc-sun fc-widget-content fc-other-month fc-past fc-first" onclick="alert(this.getAttribute('data-date'));" data-date="2016-05-29">
                              <div style="min-height: 88px;">
                                  <div class="fc-day-number">29</div>
                                  <div class="fc-day-content">
                                      <div style="position: relative; height: 0px;">&nbsp;</div>
                                  </div>
                              </div>
                          </td>

How to find 29 from it using jquery
Posted
Updated 1-Jun-16 1:46am
v2

try this

JavaScript
onclick="alert(this.getElementsByClassName('fc-day-number')[0].innerText)" 


demo:- JSFiddle[^]
 
Share this answer
 
v2
Comments
Member 12456650 1-Jun-16 7:42am    
please explain me why [0] in this context
Karthik_Mahalingam 1-Jun-16 7:48am    
this refers the td object
getElementsByClassName() function returns a collection of matched class elements, so in the td it has only one element (div) with the class fc-day-number
so to access the div we can use the index 0 , since javascript works on Zero based index

hope you understood :)
A much better option would be to use JQuery. If you have table with multiple "div" in each row with the same class you can access all of them using the following line:

JavaScript
var innerDivs = $("table td .fc-day-number");
$.each(innerDivs, function (index, value) {
var divText = value.innerText;//This will give you the value of each element.
});
 
Share this answer
 
You will need to have:
1. jQuery .class Selector[^]
2. .html() | jQuery API Documentation[^]
=>
$(".fc-day-number").html()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900