Include link if it is first element

2

I have a menu with four items. The menu is manageable, not manual via HTML.

I want to modify a link in the first Menu item, how can I do this with Jquery? I do not even know how to look to do this.

For example:

<li class='classe' onclick='window.location=\"/paginaSYS\"'><a href='/paginaSYS'>tituloSYS</a></li>

With this code above, and with the manager I can generate the four menu items, but I want to insert a link when the user clicks on the first item.

I want when the user clicks on the first menu item, it does not open the html generated by the manager, but rather a URL that I sort.

If he clicks ITEM 1 - Do not send to the page generated by the manager. www.site.com/menu1 I want you to send me an address that I wish.

I thought about doing a redirect.

    
asked by anonymous 11.03.2014 / 17:57

3 answers

4

Maybe something like this:

// Delega um evento de clique para a primeira âncora do menu mesmo que tenha sido criada após o primeiro carregamento do DOM.
$(document).on('click', '#menu a:first', function(event) {

    // Previne que a ação padrão da âncora (O redirecionamento) seja executada.
    event.preventDefault();

    // Redireciona o documento atual para outro URL.
    document.location = 'http://example.com';

});
    
11.03.2014 / 18:26
3

Example: link

I did this:

    $(document).ready(function(){
    $( "#menu a:first" ).attr( "href", "http://pt.stackoverflow.com" );
});
    
11.03.2014 / 18:18
2

I was able to solve with the following code:

$(".paginapadraoMenuBt:first").attr( "onclick", "window.open('http://www.google.com.br')");
    
11.03.2014 / 19:02