d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Dom Css > Iso Help
12Next
Add Reply New Topic New Poll
Member
Posts: 9,746
Joined: Dec 4 2008
Gold: 0.00
Jun 6 2012 08:15pm
ok so basically i need to change the style of one table when some one right click

i can't find out how to get the rule (without knowing his number into the array of all rule)

i wonder if there any other way to do this than doing a loop over all cssRules and compare if that == what i search for

what i tought

var ptr_menu = document.styleSheets[0].cssRules;
var myRule = "";
for(var i =0; i< ptr_menu.length i++)
{
if(ptr_menu[i].selectorText == "What_I_want")
myRule = ptr_menu[i];
}

i know this is probably syntax incorrect but that's not the point

if anybody have any clue would be cool

thank you for your time
Member
Posts: 29,723
Joined: Jun 11 2007
Gold: 279.52
Jun 7 2012 02:37am
let me get this strait, your trying to change height, color or whatever when someone does a right click on a div? your wanting to override browser default right clicks with your own?

This post was edited by AkuuZ on Jun 7 2012 02:37am
Member
Posts: 9,746
Joined: Dec 4 2008
Gold: 0.00
Jun 7 2012 04:55am
Quote (AkuuZ @ 7 Jun 2012 04:37)
let me get this strait, your trying to change height, color or whatever when someone does a right click on a div? your wanting to override browser default right clicks with your own?


yeah basically ... i know how to override right click i just wanted to know if there any other way to change a property for a rule with out going tru all the rule (a bit like i did)

This post was edited by djray on Jun 7 2012 04:55am
Member
Posts: 2,736
Joined: Nov 28 2009
Gold: 34.00
Jun 7 2012 05:34am
Code
function getStyle(elem, cssprop, cssprop2){

// IE
if (elem.currentStyle) {
  return elem.currentStyle[cssprop];

// other browsers
} else if (document.defaultView && document.defaultView.getComputedStyle) {
  document.defaultView.getComputedStyle(elem,null);
  return r.getPropertyValue(cssprop2);

// fallback
} else {
  return null;
}
}

// test
var e = document.querySelector('body');
console.log( getStyle(e) );


If you want all the styles for one element, just add a for loop.

Code
function getStyle(elem){

if (document.defaultView && document.defaultView.getComputedStyle) {
   
   var r = document.defaultView.getComputedStyle(elem,null);
   var rr = "";
   
   for(i = 0; i < r.length; i++){
       rr += '' + r[i] + ': ' + r.getPropertyValue(r[i]) + ';' + "\n";
   }
   return rr;

// fallback
} else {
  return null;
}
}

// test
var e = document.querySelector('body');
console.log( getStyle(e) );


This doesn't exactly seem like you want though, because you are contradicting yourself with your latest post. Is it that hard to be clear? Guess so.
Why would you ever want to change the CSS document to make a CSS change? Just append for example into the style attribute: style="background-color: red !important;"

This post was edited by eagl3s1ght on Jun 7 2012 05:36am
Member
Posts: 9,746
Joined: Dec 4 2008
Gold: 0.00
Jun 7 2012 08:15am
Quote (eagl3s1ght @ 7 Jun 2012 07:34)
Codefunction getStyle(elem, cssprop, cssprop2){

// IE
if (elem.currentStyle) {
  return elem.currentStyle[cssprop];

// other browsers
} else if (document.defaultView && document.defaultView.getComputedStyle) {
  document.defaultView.getComputedStyle(elem,null);
  return r.getPropertyValue(cssprop2);

// fallback
} else {
  return null;
}
}

// test
var e = document.querySelector('body');
console.log( getStyle(e) );

If you want all the styles for one element, just add a for loop.

Codefunction getStyle(elem){

if (document.defaultView && document.defaultView.getComputedStyle) {
   
    var r = document.defaultView.getComputedStyle(elem,null);
    var rr = "";
   
    for(i = 0; i < r.length; i++){
        rr += '' + r[i] + ': ' + r.getPropertyValue(r[i]) + ';' + "\n";
    }
    return rr;

// fallback
} else {
  return null;
}
}

// test
var e = document.querySelector('body');
console.log( getStyle(e) );

This doesn't exactly seem like you want though, because you are contradicting yourself with your latest post. Is it that hard to be clear? Guess so.
Why would you ever want to change the CSS document to make a CSS change? Just append for example into the style attribute: style="background-color: red !important;"


ty for your help .... sorry for been unclear =(
i think from that i can get what i want

/e what i exactly want to do is:

1- change display:none into display:table;
2- change the position of that table

This post was edited by djray on Jun 7 2012 08:17am
Member
Posts: 2,736
Joined: Nov 28 2009
Gold: 34.00
Jun 7 2012 08:32am
Quote (djray @ 7 Jun 2012 15:15)
ty for your help .... sorry for been unclear =(
i think from that i can get what i want

/e what i exactly want to do is:

1- change display:none      into      display:table;
2- change the position of that table


Code
var t, l = 50;
document.querySelector('table').setAttribute('style', 'display: table; position: absolute; top: ' + t + '; left: ' + l + ';' );


on release:
Code
document.querySelector('table').setAttribute('style', '');


I think you were complicating things, wanting to get the style etc.

This post was edited by eagl3s1ght on Jun 7 2012 08:32am
Member
Posts: 9,746
Joined: Dec 4 2008
Gold: 0.00
Jun 8 2012 05:29pm
on release:
Code
document.querySelector('table').setAttribute('style', '');


I think you were complicating things, wanting to get the style etc.[/QUOTE]

but this way is in jquery isn't it?

because i can't use jquery in the context of my class

Member
Posts: 2,736
Joined: Nov 28 2009
Gold: 34.00
Jun 8 2012 05:58pm
Quote (djray @ 9 Jun 2012 00:29)

but this way is in jquery isn't it?

because i can't use jquery in the context of my class


lol no, that isn't jquery, its simple javascript. althuogh .querySelector() is incompatible BEFORE IE8. You can just use getElementsByName('table')[0] instead though.

The jQuery version would look like this..
Code
$('table').attr('style', '');


The fact that you mixed those up makes me concerned and abit annoyed. Do your research, don't make people do it for you.

This post was edited by eagl3s1ght on Jun 8 2012 05:58pm
Member
Posts: 9,746
Joined: Dec 4 2008
Gold: 0.00
Jun 9 2012 08:41am
Quote (eagl3s1ght @ 8 Jun 2012 19:58)
lol no, that isn't jquery, its simple javascript. althuogh .querySelector() is incompatible BEFORE IE8. You can just use getElementsByName('table')[0] instead though.

The jQuery version would look like this..
Code
$('table').attr('style', '');


The fact that you mixed those up makes me concerned and abit annoyed. Do your research, don't make people do it for you.


sorry for being learning
Member
Posts: 428
Joined: Jan 20 2006
Gold: 0.00
Jun 9 2012 05:22pm
Quote (eagl3s1ght @ Jun 8 2012 11:58pm)
The fact that you mixed those up makes me concerned and abit annoyed. Do your research, don't make people do it for you.


Ignore his rudeness, he doesn't understand that some people are new.

On another note, instead of changing the style attribute inline you should just add a class that has those styles attached (and remove the class when you want them gone).
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll