Не уверен, имеет ли смысл смысл или нет.
Но то, что я делаю, ищет якорь внутри div с классом баннера. Затем, пытаясь написать href как www.domain.com/catno.prd.
Однако, поскольку то, что я построил, сидит на www.domain.com/foo/bar/, он возвращается с www.domain.com/foo/bar/catno.prd
Как я могу удалить /foo/bar/, чтобы ссылка возвращалась только в домене?
Вот что у меня есть
$('.banner a').attr('href', function() {
return $sd(this).attr('catno') + '.prd'
});
Спасибо за любую помощь :)
Просто добавьте ведущий /
:
$('.banner a').attr('href', function() {
return '/' + $sd(this).attr('catno') + '.prd'
});
@RGraham является правильным, но attr был обесцененным использованием prop
$('.banner a').prop('href', function() {
return '/' + $sd(this).prop('catno') + '.prd'
});
The difference between attributes and properties can be important in specific situations. Before jQuery 1.6, the .attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior. As of jQuery 1.6, the .prop() method provides a way to explicitly retrieve property values, while .attr() retrieves attributes.