Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 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
    Regular Coder
    Join Date
    Aug 2010
    Posts
    974
    Thanks
    19
    Thanked 212 Times in 210 Posts
    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; 08-25-2011 at 04:38 PM. Reason: careless omition

  • #3
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    <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; 08-25-2011 at 09:27 PM.

  • #4
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    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);

  • Users who have thanked devnull69 for this post:

    anthor (08-25-2011)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •