Это может быть глупый вопрос, но я не могу найти подходящее решение для этого. У меня есть простой ajax:
jQuery( document ).ready( function() {
jQuery( 'body' ).on( 'click', 'a', function( event ) {
event.preventDefault();
var $this = jQuery( this );
var url = $this.attr( 'href' );
if ( '#' !== url ) {
jQuery.ajax({
url: url,
beforeSend: function() {
console.log( 'before send' );
},
error: function() {
console.log( 'error' );
},
success: function( content ) {
// here insert target URL's #content into #main. This works just fine.
jQuery( '#main' ).html( jQuery( content ).find( '#content' ) );
// Trying to get href of a <link> from <head>. This gives me 'undefined'
var href = jQuery( content ).find( '#id-of-link-element' ).attr( 'href' );
console.log( href );
}
});
}
});
});
Теперь, как получить атрибут href ссылки, которая находится в начале целевой страницы? Я попытался получить его, как показано в моем коде выше, но он выскочил «undefined» в консоли.
С уважением, Дэн.