0

i'm doing a goto link in web page, with an input text aside it. the goto link appear both on top and bottom of webpage.

<div class="gotopage">
    goto page<input type="text" class="page_i"/>
    <a href="###" class="Goto">Go</a>
</div>

in jquery, i need to get text beside link:

$('a.Goto').live('click',function(){
    window.location.href = ...;
});

how to get text value, it shouldn't be id, for id appear twice.

0

3 Answers 3

2

Use prev() to get sibling text input:

$('a.Goto').live('click',function(){
    window.location.href = $(this).prev('.page_i').val();
});
Sign up to request clarification or add additional context in comments.

Comments

0

Wrap the text in a span tag:

<div class="gotopage">
 <span>goto page</span><input type="text" class="page_i"/>
 <a href="###" class="Goto">Go</a>
</div>

Then select it

$('a.Goto').live('click',function(){
   window.location.href = $(this).closest('span').text();
});

Comments

0

You can get text of an input box by using this code

<script>
$('a.Goto').live('click',function(){
    txt=$('.gotopage .page_i').val();
    alert(txt);
});
</script>

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.