Jquery returns index -1 always
Posted
by
jfreak53
on Stack Overflow
See other posts from Stack Overflow
or by jfreak53
Published on 2012-09-13T21:34:12Z
Indexed on
2012/09/13
21:38 UTC
Read the original article
Hit count: 194
This is my index code that I use to return the buttons parent div's index:
j('#optionform').index( j(this).parent() )
I'm trying to find out the DIV index of the button clicked, so I can remove the DIV.
The HTML layout is like so:
<form id="optionform" onsubmit="return false;">
<label><input type="checkbox" id="s_name" value="s_name"> Survey Name </label>
<label><input type="checkbox" id="s_type" value="s_type"> Survey Type </label><br>
Filter Results:<br>
<div id="template" style="display: none;">
Column: <select id="fcolumn[]">
<option></option>
<option value="s_name">Survey Name</option>
<option value="s_type">Survey Type</option>
</select><br>
Filter Type: <select id="ftype[]">
<option></option>
<option value="=">Equals</option>
<option value="LIKE">Like</option>
</select><br>
Filter content: <input type="text" id="fcontent[]"><br>
<img src="images/add.png" width="32px" onclick="addTemp(); return false;">
<img src="images/delete.png" width="32px" onclick="alert(j(this).attr('src')); remTemp(j('#optionform').index( j(this).parent() )); return false;">
</div>
<div class="template" style="display: block;">
Column: <select id="fcolumn[]">
<option></option>
<option value="s_name">Survey Name</option>
<option value="s_type">Survey Type</option>
</select><br>
Filter Type: <select id="ftype[]">
<option></option>
<option value="=">Equals</option>
<option value="LIKE">Like</option>
</select><br>
Filter content: <input type="text" id="fcontent[]"><br>
<img src="images/add.png" width="32px" onclick="addTemp(); return false;">
<img src="images/delete.png" width="32px" onclick="alert(j(this).attr('src')); remTemp(j('#optionform').index( j(this).parent() )); return false;">
</div>
<div class="template" style="display: block;">
Column: <select id="fcolumn[]">
<option></option>
<option value="s_name">Survey Name</option>
<option value="s_type">Survey Type</option>
</select><br>
Filter Type: <select id="ftype[]">
<option></option>
<option value="=">Equals</option>
<option value="LIKE">Like</option>
</select><br>
Filter content: <input type="text" id="fcontent[]"><br>
<img src="images/add.png" width="32px" onclick="addTemp(); return false;">
<img src="images/delete.png" width="32px" onclick="alert(j(this).attr('src')); remTemp(j('#optionform').index( j(this).parent() )); return false;">
</div>
</form>
But it always returns -1
in the index.
© Stack Overflow or respective owner