Frage

Is there a way to dynamically change the content inside the tag?, throught jquery or javascript?

I am not using php or any server side script. I am using backbone.js and hence i have a .html file.

I have come to a situation where i would need to type in base path.

Like

<base href="www.google.com" />

I have searched around and i havent got anywhere.

Probably this is not possible at all, but just wanted to check it here in stackoverflow.

War es hilfreich?

Lösung

Using jQuery. Here is jsFiddle I've made http://jsfiddle.net/uQVeN/

HTML:

<base href="www.google.com" />
<div id="valueBefore"></div>
<div id="valueAfter"></div>

JS:

$(document).ready(function(){
    $('#valueBefore').text( $('base').attr('href') );
    $('base').attr('href','kjhsgdkjahgdjkahgdf');
    $('#valueAfter').text( $('base').attr('href') );
});

Will produce:

www.google.com
kjhsgdkjahgdjkahgdf
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top