1

my code is

<div id="fields">
<form id="question-form">  <input type="hidden" name="question-main" value="<?php echo mysql_prep($_GET['ques']);?>" /></form>

<a class="vote-up-off">up vote</a>

<span class="vote-count-post"><?php echo $row["upvotes"]+$row["downvotes"];?></span>

 <a class="vote-down-off" id="<?php echo mysql_prep($_GET['ques']);?>" >down vote</a>

 <a class="star-off" href="#">favorite</a>
</div>

and my jquery code is

$("document").ready(function(){
$(".vote-up-off").click(function(){
// here i want the id of form field and votecountpost field which is up and down to this field
})
})

the div field repeats again and again as the field present on database.So i want to get the particular field id using jquery and will perform some action using jquery. How to find this?

3 Answers 3

2
        $("document").ready(function () {
            $('.vote-up-off').live('click', function () {
                var formId = $(this).parents('form').attr('id');
                var voteCountPost = $(this).next('.vote-count-post').attr('id');
            });
        });

for form u can add class="VoteForm". so that it take that form attribute id in parents('').

        $("document").ready(function () {
            $('.vote-up-off').live('click', function () {
                var formId = $(this).parents('form.VoteForm').attr('id');
                var voteCountPost = $(this).next('.vote-count-post').attr('id');
            });
        });
Sign up to request clarification or add additional context in comments.

1 Comment

it works...thanx for the help...is there any another way..excpt parent()..to go up or down..????
1

Each div needs its own id. If the divs are created in a PHP loop, you can do this by incrementing a variable:

$divNumber=1;
while ( $row = mysql_fetch_array($results) )
{
    echo '<div id="fields-'.$divNumber.'">';
    // echo div content here
    echo '</div>';
    ++$divNumber;
}

Comments

0

in this line:

$(".vote-up-off).click(function(){...

it should be:

$(".vote-up-off").click(function(){...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.