Hello take a look at my code then I'll tell you what error I get...

var Top = document.getElementById("topmargin").value;
        var Left = document.getElementById("leftmargin").value;
        var Background_Color = document.getElementById("backgroundcolor").value;
        var Border_Width = document.getElementById("borderwidth").value;
        var Border_Type = document.getElementById("bordertype").value;
        var Border_Color = document.getElementById("bordercolor").value;
        var num = id+1;
        var new_id = "a"+num;
        
        document.getElementById(new_id).style.top = Top;
        document.getElementById(new_id).style.left = Left;
        document.getElementById(new_id).style.backgroundcolor = Background_Color;
        document.getElementById(new_id).style.border = Border_Width+" "+Border_Type+" "+Border_Color;

The element with that id has been created and I still get this error when I try to style it...

Uncaught TypeError: Cannot read property 'style' of null
edit_divjs.js:92
(anonymous function)/PHP%20Projects/StyleStop/#:1
onclick/PHP%20Projects/StyleStop/#:2

My browser is Google Chrome.

Member Avatar for stbuchok

Does this document.getElementById(new_id) return null?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.