This is ugly and there has to be a better way to write it in jQuery

$(this).parent().parent().parent().parent().find('[name=reply_to_id]');

Thats just stupid looking, but its the best way i can think of writing it. I tried parentsUntil('li') but that didnt work at all and i also tried parents('li') and closest('li'). Isnt there something in jQuery with the equivalent of:

$(this).firstParentThatMatchesThis('li').find('[name=reply_to_id]');

If not i think ill try submitting it to the jQuery core...

Here is my HTML (long so i put it on pastebin): http://pastebin.com/FypJ9WGe

Working on getting JSFiddle in there...

Answers


Try this:

$(this).parents("li").eq(0).find('[name=reply_to_id]');

Example: http://jsfiddle.net/FvzT9/

But, closest should work as well:

$(this).closest("li").find('[name=reply_to_id]');

Example: http://jsfiddle.net/FvzT9/1/


Need Your Help

PHP regular expression for multiple tables

php regex preg-match-all

I need help with building regular expression for text separating.

IBM-MQ reader in .net XMS to ack processed messages one-by-one

c# .net websphere-mq

I am implementing a component that reads all the messages off a specific queue as they are available but should only remove messages from the queue asynchronously, after the message contents has been

Spring MVC: generate ModelAndView programmatically

java spring spring-mvc

I am wondering is it possible to generate ModelAndView's output programatically and not via controller's return parameter. For example:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.