Bind value of elements
Can i execute custom function when some properties of html tag is changed?
For example:
HTML code
<a id="link1">title</a>
<a id="link2">title</a>
When we change link2 text i want to change link1 text. So i want something like DataBinding in Windows Presentat开发者_C百科ion Foundation.
We are changing link2: $('#link2').text('blablablaballba'); and value of link1 must be "blablablaballba". I dont want to write additional code $('#link1').text('blablablaballba'); and so on. link1 must be changed automatically.
You can write:
$('#link2, #link1').text('blablablaballba');
You can use a periodic interval to check the contents, like:
var timerID;
function watchLink2() {
var el = document.getElementById("link2");
return function () {
if (el.innerHTML != "title") {
document.getElementById("link1").innerHTML = el.innerHTML;
clearInterval(timerID);
}
};
}
timerID = setInterval(watchLink2(), 200);
But, er..., how do you think the attribute's value is changed?
精彩评论