开发者

How can I get access to the items within "this"

How can I get access to the items within "this" so that I can chain further elements onto a "this" object?

I am sure I am not understading something and doing it the long way around, but currently taking a "this" object and manually parsing out the string of items in the element so I can then add further specification

I originally thought I could just:

$(this) + " ul li";

but that just seems to try to add a string to [object HTMLDivElement]

So I then manually extracted and contacenated all the elements together as a string:

function cleanThis(el) { return el.replace(/^ +/,"").replace(/ +$/,"").replace(/  +/g," ") }
function parseThis(el) { return el.tagName + (el.id?"#"+cleanThis(el.id):"") + (el.className?"."+cleanThis(el.className).replace(/ /g,"."):"") }

var eachThis = $(parseThis(this)  + " ul li");

This seems like I am recreating the wheel and that I should be able to access the information I need in JQuery or Javascript

So if $(this) = jQuery(div#nav)

How can I g开发者_运维技巧et access to "div#nav" so that I can actually add further specification such as the example above with eachThis (adding on: " ul li")


I think you're looking for .find().

$( this ).find( 'ul li' );

Another way is to provide the containing element as a parameter:

$( 'ul li', $( this ) );


You want to add a <ul> to whatever node is inside $(this)?

$(this).append('<ul><li>');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜