Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 06, 2012 12:08 PM by mani2009it
Member
207 Points
82 Posts
Apr 06, 2012 11:09 AM|LINK
Hi everyone,
I want to get next item text() and prev item text() of selected item of dropdown through jquery. HOw???
<select id=”testselect”> <option>Value 1</option> <option selected="selected">Value 2</option> <option>Value 3</option> <option>Value 4</option> </select>
I want to get "Value 3" and "value 1" on selection of value 2
Star
9339 Points
1448 Posts
Apr 06, 2012 11:18 AM|LINK
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { alert($("select[id=testselect] :selected").prev().html()); alert($("select[id=testselect] :selected").next().html()); }); </script> ---------------------- <select id="testselect"> <option>Value 1</option> <option selected="selected">Value 2</option> <option>Value 3</option> <option>Value 4</option> </select>
Thanks
Apr 06, 2012 12:08 PM|LINK
$("#testselect option:selected").prev().text()
$("#testselect option:selected").next().text()
mani2009it
Member
207 Points
82 Posts
Get next selected dropdown text ??
Apr 06, 2012 11:09 AM|LINK
Hi everyone,
I want to get next item text() and prev item text() of selected item of dropdown through jquery. HOw???
I want to get "Value 3" and "value 1" on selection of value 2
me_ritz
Star
9339 Points
1448 Posts
Re: Get next selected dropdown text ??
Apr 06, 2012 11:18 AM|LINK
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { alert($("select[id=testselect] :selected").prev().html()); alert($("select[id=testselect] :selected").next().html()); }); </script> ---------------------- <select id="testselect"> <option>Value 1</option> <option selected="selected">Value 2</option> <option>Value 3</option> <option>Value 4</option> </select>Thanks
mani2009it
Member
207 Points
82 Posts
Re: Get next selected dropdown text ??
Apr 06, 2012 12:08 PM|LINK
$("#testselect option:selected").prev().text()
$("#testselect option:selected").next().text()