Web Analytics Made Easy -
StatCounter create element("a") problem - CodingForum

Announcement

Collapse
No announcement yet.

create element("a") problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • create element("a") problem

    var newlink = document.createElement("a");
    newlink.setAttribute("class", "mhs uiButton");
    newlink.setAttribute("role", "button");
    newlink.setAttribute("href", "http://www.facebook.com/#");
    newlink.setAttribute("onlick","FriendBrowserCheckboxController.makeFriendRequest(this, '+javaedit.text+'); return false;");
    alert(newlink.classname);

    why alert newlink.classname return as undefined ? i have set class = mhs uiButton already,should be return mhs uiButton?

  • #2
    Your code is OK in firefox but not ie

    checkout this link

    http://www.quirksmode.org/bugreports...d_with_th.html

    alert(newlink.classname);

    should be

    alert(newlink.className);
    Last edited by DaveyErwin; Aug 25, 2011, 11:38 AM. Reason: careless omition

    Comment


    • #3
      <DIV class=UIImageBlock_Ext>
      <DIV id=friend_browser_unit_100002258463790 class="friendBrowserUnit ">
      <INPUT class=friendBrowserID value=100002258463790 type=hidden name=friend_browser_id[] autocomplete="off">
      <DIV id=friendBrowserActionId_100002258463790 class="friendBrowserAddAsFriend stat_elem">
      <A class="mhs uiButton" role=button onclick='FriendBrowserCheckboxController.makeFriendRequest(this, "100002258463790"); return false;' href=" http://www.facebook.com/#">
      <I class="mrs img sp_du7a4w sx_4c9e49">
      </I>
      <SPAN class=uiButtonText>Add Friend</SPAN>
      </A>
      </DIV>
      </DIV>
      </DIV>

      since i have create all the attributes like this:

      var newlink = document.createElement("A");
      newlink.setAttribute("className", "mhs uiButton");
      newlink.setAttribute("role", "button");
      newlink.setAttribute("href", "http://www.facebook.com/#"); '
      newlink.setAttribute("onclick",function() { FriendBrowserCheckboxController.makeFriendRequest(this, "100002258463790");
      return false;});
      FriendBrowserCheckboxController.makeFriendRequest(newlink, "100002258463790"); alert(newlink.className);

      but the function FriendBrowserCheckboxController.makeFriendRequest still can't work,what's wrong?
      Last edited by anthor; Aug 25, 2011, 04:27 PM.

      Comment


      • #4
        You should forget about setAttribute. Most of the time you can use the element properties instead. In case of "on" event handlers you even have no other choice

        Code:
        var newlink = document.createElement("a");
        newlink.className = "mhs uiButton";
        newlink.setAttribute("role", "button");
        newlink.href = "http://www.facebook.com/#";
        newlink.onclick = function() { 
           FriendBrowserCheckboxController.makeFriendRequest(this, "100002258463790");
           return false;
        };
        FriendBrowserCheckboxController.makeFriendRequest(newlink, "100002258463790"); alert(newlink.className);

        Comment

        Working...
        X