简体   繁体   中英

Jquery: is there another way to write this, maybe using .attr?

I thought I could re-write the line below:

$('a').filter('[hash=' + inview + ']');

to something like this:

$('a').attr(href, inview);

obviously with var inview = yada yada yada defined above it.

or is there another way to write the first line up there,

using jquery and getting rid of the [hash=' for something like.attr or.something(inview)?

$('a[hash=' + inview + ']');

That should do it.

You want something like:

$('a[hash="' + inview + '"]')

$('a').attr('hash', inview); , which is what I assume you meant for your second line, actually sets the hash attribute to inview.

$('a').attr(href, inview);

For reference that would set the href of all a elements to inview

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM