简体   繁体   中英

How to get text from div with a data-bind?

<div class="col-num-two" data-bind="CurrentJob.addr">I need this text</div>

The data is AJAX'd in and I need to change the text inside. I'm just using a 1 second timeout, but how do I select that div since there is no 'id' ?

After the timeout fires use code like this:

var currentJobAddr  = document.querySelector ("div[data-bind='CurrentJob.addr']");
if (currentJobAddr)
    currentJobAddr  = currentJobAddr.textContent;
else
    alert ('Current job addr not found.')


See the code in action at jsFiddle.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM