Jquery captures div id in scroll and changes title

0

I have a page with a title and several divs with different subjects and IDs of my own, I would like that when I go down the screen, jquery captures the ID that is visible and places it in the title.     

asked by anonymous 02.02.2016 / 02:09

1 answer

1

To get the first ID using jquery you would have 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 in place 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 were 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

    
02.02.2016 / 05:12