Jquery captures ID of div in scroll and changes title

Asked

Viewed 128 times

0

I have a page with a title and several Ivs with different subjects and their own Ids, I would like that when descending the screen, jquery captures the ID that is visible and puts in the title.

  • When you say "put it in the title" you mean "<title>dentro da <head>`?

1 answer

1


To get the first ID using jquery you could use the code below, which would bring you an object:

code 1

$( 'tag[id!=""]:visible:first' );

Where the tag would be where the id is. If the id identifies a div, then instead of the tag you put div. The same for input.

To modify the title you can use the code:

code 2

$( 'title' ).text("novo título");

If your tag in code 1 was an input, then you implement code 2 as follows. Ex:

$( 'title' ).text( $( 'input[id!=""]:visible:first' ).val() )

If you want you can take a look at the jquery documentation

Browser other questions tagged

You are not signed in. Login or sign up in order to post.