JQuery :: Get The Index Of An Element Clicked?
Apr 13, 2010If I have a group of elements, <li>'s in a <ul> for example, is there a way I can know I clicked on n of them?
[Code]...
If I have a group of elements, <li>'s in a <ul> for example, is there a way I can know I clicked on n of them?
[Code]...
I'm trying to find the currently clicked index of .accordion_trigger from within another element.
When inside the .accordion_trigger click event I can simply do the below to get the current clicked index:
Code:
$('.accordion_trigger').click(function(){
var index = $('.accordion_trigger').index(this);
}
return false;
});
Obviously this doesn't work when called from within another element. I understand that 'this' is part of the problem but can't seem to find a way to form the code in such a way for it to produce a valid result. Thus far I only get -1 or 0.
When .accordion_trigger is clicked it has an "$(this).toggleClass('active').next().slideDown();" applied so in theory I shold be able to search for which of the .accordion_trigger's are "active".
I've also tried doing this via the below method but to no avail:
Code:
var current = $('.accordion_trigger');
current.each(function() {
if ($(this).hasClass('active')) {
[Code]....
I want to know the index of the option that a user clicks on in a
multiple-select object (regardless of whether he selected or deselected
it). This seems fairly simple but I can't seem to figure out how to do
it. Does anybody know how to do this?
I'm trying to get the index of a div when its the same mark up for each set. I want to return index of '1' when a second "yo" is clicked in any "a" and '0' if the first "yo" is clicked in any "a". If i clicked the "yo" which has the color #330000, then i should get 1 not 5. This seems like a simple task but i cannot get it to work.
[Code]...
I have a calendar in which each day is a separate div, and all these are within a container div #cal. When a user mouses over one of the days, I want to figure out the index number of that day's div within #cal. Simplified example:
<div id="cal">
<div onmouseover="findIt()" id="nov1">1</div>
<div onmouseover="findIt()" id="nov2">2</div>
<div onmouseover="findIt()" id="nov3">3</div>
</div>
I can easily get the index of #nov2 from Firebug if I do this in the console:
$('#cal div').index($('#nov2')
But, I can't figure out how to write a function so that I don't need to assign an id to each day div. I'd like to be able to just take "this" from the moused-over div, and pass that to a function that can turn it into the needed index.
I have a bunch of elements with multiple classes like this:
<div class="foo bar">
<div class="foo bar snafu">
<div class="foo bar">
I can get all these elements in an array like this:
$ (".foo,.bar")
My question is - is there an elegant way of getting the index (in this array) of the element that has the "snafu" class? Or should I just iterate through the array until I find the wanted element and then remember its index?
I have many small divs which have a particular class. so based on this class only i am getting the click event on them. now what I want is to get the index of one single div one which we clicked.. I am not remembering how to do it..
View 9 Replies View RelatedI try to make a dynamic form with inputs depended on selects fields. My method works in static form but I don't know how to use it in dynamic one.
JSON function ( to control correct input with select)
$(document).ready(function() {
$('select.sf').change(function() {
[code]....
My question is quite simple with an example:
[Code]...
It is possible to make a script that hides the element clicked and this way hide the items I want.
View 1 Replies View RelatedIn my html head tag i have a script like as below
$(
function
(
)
[Code].....
I am trying to update some values on the page when an img is clicked. There are many img tags on the page. I am not sure how can i determine which one is clicked.
Do i have to add an onclick event to my img tags with some id parameter or is there a possibility to detect which element is clicked on the page without calling a function?
I have several <a> tags with the class 'a-menu-description', and an equal number of divs with the class 'menu-description'.
I am trying to get it so that only one div opens for the appropriate <a> tag, but when I click any of the <a> tags, all of the divs open up.
Here is my code:
Does anybody know what I can add in so that only the div associated with the <a> tag opens as opposed to all of them?
[url]
I am working on a little project with fullcalendar but while writing some callback functions stumbled upon an issue: Fullcalendar generates html that looks like this: <a><span></span><span></span><span></span></a>.
Now there is an eventClick callback that is fired when clicking on that <a> element. However, in that callback I would like to know which <span> element was clicked.
I have an html file that looks like the following.
<div id="outline-container-1_1" class="outline-3">
<h3 id="sec-1_1"><span class="section-number-3">1.1</span> Counting </h3>
<div class="outline-text-3" id="text-1_1">
[Code]...
I'm trying to determine a better method of finding the index value of a form element. I need to find it because the JavaScript validation class has a function for validating a single form element, but it requires that the index number of the element in the form be passed in.Currently I am accomplishing this by a function that I wrote which I call for each field I want to validate:
function getIndex(element)
{
for (var i=0; i<document.thisForm.elements.length; i++)
[code]....
Let's say I have a table with 5 rows;
<table id="tbl">
<tr><td>Please</td></tr>
<tr><td>help</td></tr>
<tr><td>me</td></tr>
[Code].....
Now if someone clicks on the row with content "help" (2nd), I want to catch the click with jquery .click() and know within the jquery code that the user clicked on the 2nd <tr> element within table#tbl.
If someone clicks on the <tr> with content "this", my jquery code has to return 5, because its the 5th row.
i am trying to make my custom made combobox with using jquery and ul li menus. So when mouse clicked to the li element i have to read its value and set its parent to the clicked element value etc. Basic selecting method. So how can i read the clicked li element value and set that value to the parent of it. Here my structure.
I want to read clicked li element text not other one i tried var htmlStr = $(this).text;
[Code]...
How to get the index number of getElementsByTagName("input") array on clicked field? i.e. when i clicked a field name "f03" of first record, i want to print(alert msg) the index value as 0, for second record 1 respectively.for that i want to write javascript for onclick event.
View 3 Replies View RelatedTrying to return the DOM 0 element index from within the html
Example: <input type="text" onfocus="alert(this.element)" />
I do not want to use IDs any way to do this?
i need to know weather or not there is a way to put the cursor below (z-index wise) a div element or make it so that you can click through the div element.
View 3 Replies View RelatedI'm using the jquery topZIndex plugin in my application. It's working great. Now I have a situation though, where I would like to return the element with the highest z-index on the page. The plugin has a function that will return the highest z-index, but it's a value, not an object.
View 2 Replies View Relatedi am trying to build a function that takes into account a click event and SHIFT key press event on a particular element.
so for example, i want to do something only when i click a box WHILE pressing the SHIFT key.
how do i program this using jquery?
I have an <input type="checkbox"> whose immediate parent is an <a> tag. The <a> is significantly larger than the <input>.
I want the checkbox to toggle on/offwhether the <a> is clicked or the checkbox itself. I also wantto store the value of the checkbox after it changes.
This sounds simple butI'm having trouble with the event bubbling (as in, I don't understand it).
Here is my current code.
HTML:
as you can tell by the following statements, i'm new to jQueryI'm trying to do the following (in plain english) without too much success.. ) when document ready.. 2) find the element with id 'next'.3) pull / take all 'li' elements, and perform so and so, all whilst excluding 'last' element.
$(document).ready(function() {
$('#next').click(function() {
$('li').each(function() { //for each li ..
[code]....
I'm trying to swap the class of an element when it's clicked on. Using jquery 1.6.1, here's what it looks like:
[Code]....
Now, for the sake of brevity�*i omitted some other stuff that is happening when they're clicked on. The problem is that the click event for .unchecked_container is firing fine and the class is changed, BUT when clicked on again�*the '.checked_container' click event is NOT firing.
I have an array "arr" that is an array of objects. Each object has the same 7 properties.I want to find the index of the object with a property that matches a certain value x in the array arr. The array has hash tables associated with it.
arr [ obj [ i ] . property1 + "_" + obj [ i ] . property2 ] = arr [ i ] ;
so whats the index of the object where .property1 = x ?