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 5 of 5

Thread: Object document

  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,383
    Thanks
    264
    Thanked 32 Times in 31 Posts

    Object document

    Is there a smaller object definable than the document.

    for example:

    Code:
    document.xxxxxxxx= function()
    {
    //do something
    }
    but this is whole document in an object.

    what if i just want part of the document in an object, such as just the text part of the body or a particular div content within the body.

    isnt there a smaller isolator than document? i know you can do document.formname but what if it does not have a name like a div or a span

    thanks

    UPDATE: i suppose my answer is here somewhere http://www.w3schools.com/jsref/dom_obj_document.asp


    Maybe something like

    Code:
    document.getElementsByTagName( 'div' ).xxxxxxx=function()
    {
    //do something only within any div or a particular div if possible.
    }
    Nevermind i guess i been at this toooo long today... lol... it went right over my head that i could do an id on a div, heck i do it all the time wow... guess im tired... i think i got this now... thanks
    Last edited by durangod; 10-21-2013 at 04:59 PM.

  • #2
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,383
    Thanks
    264
    Thanked 32 Times in 31 Posts
    ooops i thought i had it but its not working

    inside the html i have

    Code:
    <div id="prevent">
    text 
    </div>

    and then i made a js file with this in it
    Code:
    document.getElementById('prevent').oncontextmenu = function () 
    {
            alert('you right clicked inside this div!');
           return false;
    };

    if not div i can use a table too because there is only one table in this file.

    and i know i can just do the div in the file with the js inside it easy, but that does not pass validation due to oncontextmenu not being an valid attribute.
    Last edited by durangod; 10-21-2013 at 02:43 PM.

  • #3
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    Your code is running fine in Firefox, Chrome and IE10 ... which browser are you using? Does this example work for you? http://jsbin.com/AfihovA/1

  • Users who have thanked devnull69 for this post:

    durangod (10-21-2013)

  • #4
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,383
    Thanks
    264
    Thanked 32 Times in 31 Posts
    hi yeah that is strange, i was using IE9 and FF.. yes that example in link works fine..

    maybe it cached my old page. let me clear things out and try again... thanks for the heads up.

  • #5
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,383
    Thanks
    264
    Thanked 32 Times in 31 Posts
    got it thanks so much... the problem is i did not have my js file src call after the close div, once i put it after the div it works.

    i thought putting it in the head was ok, but i guess not in this case..

    thanks so much devnull69


  •  

    Posting Permissions

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