HomeHome  
  • WelcomeWelcome  
  • Events  
  • PublicationsPublications  
  • FAQFAQ  
  • SearchSearch  
  • MemberlistMemberlist  
  • UsergroupsUsergroups  
  • RegisterRegister  
  • Log inLog in  
  • You are not connected. Please login or register


    Add an attribute for an object

    avatar
    • Administrator

        Reputation : 315
        Registered on : 2012-02-22
        Posts : 2317
        School of codes courses: coming soon
      Add an attribute for an object

      Description



      Add an attribute class, id, placeholder, etc.. for an object using Javascript



      Set up



      You want to make your replay box just like on twitter? (Compose new Tweet...) just use the following codes. The Javascript will do the work for you.



      This code works on the section that support the class you choose...

      First, Go to Admin CP -> Modules -> JavaScript Codes Management -> Create a new JavaScript and paste the following code:



      Table-Code: (ID)

      Code:
      $(document).ready(function(){
      document.getElementById('IDATTRIBUTE').attribute = "value";
      });

      Table-Code: (CLASS)

      Code:
      $(document).ready(function(){
      document.getElementByClass('CLASSATTRIBUTE').attribute = "value";
      });


      Set this javascript code "In all Pages"



      Here you are an example of a code edited:
      Forum version: PunBB

      Description: Paste a message, that will be deleted on click, in the textarea

      Code:
      Code:
      $(document).ready(function(){
      document.getElementById('text_editor_textarea').placeholder = "Write your message in this ares";
      });




      Customize the tutorial



      Edit "CLASS/IDATTRIBUTE" with the id/class of the object you want to add the attribute; change "Attribute" with the attribute-name you want to add and "value" with the value of the attribute



      Technical problems



      The tutorial was tested on this forum and with the browser Google Chrome; If you notice that the tutorial doesn't work for a browser or for a version of forum (PhpBB2, PhpBB3, PunBB, Invision) contact an administrator and we will fill this field with your reporting.



      Thanks, the staff




      For every problem or question please, contact us in the section Support for the tutorials, The staff will answer you as soon as it is possible...




      Friendly,
      The team of the Forum of Codes.



      Niko wants you in the team Guest

      Community manager and Administrator at Forumattivo.com

      avatar
      • Veteran staff member

          Reputation : 19
          Registered on : 2012-04-05
          Posts : 77
        Just so you know, its .getElementsByClass()
        You missed the 's' off of elements.

        And also, since jQuery is on our forums, your better off using jQuery for getting classNames, as this deals with supporting multiple browsers. getElementsByClass is only supported in modern(ish) browsers, and won't work for everyone. So you can write a generic getClass() function which deals with browser support or just use the jQuery since its their in the page.

        Also, accessing an attirubte via dot notation like that requires the attribute to be already set on some browsers. You may like to look at the setAttribute() function ;)


        YOUR BANNER HERE
        728x90
        DMCA.com Protection Status
        Free forum | © PunBB | Free forum support | Contact | Report an abuse | Free forum