简体   繁体   中英

how to display content using anchor tag

I want to preview content,when i click on the anchor tag,

                    var profiledemo = profiles.split(",");
                    for (var pd = 0; pd < profiledemo.length; pd++) {
                        var mydiv = document.getElementById("Profile");
                        var aTag = document.createElement('a');
                        aTag.setAttribute('href');
                        aTag.innerHTML = profiledemo[pd];
                        mydiv.appendChild(aTag);                               
                        aTag.onclick = function () {
                            alert("profiles anchor tag called");

                        }
                    }

I am able to display multiple docs and for those docs i put anchor tag using above,now I want,when user click on the particular tag I have to display that doc content which is in database.

Binding events in plain javascript is not much convenient, cause IE and other browsers offer different API, so you'll have to check for browser type and maintain cross-browser compatibility. You'd better use jQuery.

$(aTag).click(function() { alert("..."); });

By the way is it necessary to construct the anchor programmatically? I'd recommend to embed html anchor and display when necessary.

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