Good all the time of the day gentlemen. We have:

// php код <a style=\"{cursor:pointer;display:inline;}\" id=\"si_aa".$m4["id"]."\"> <input type=\"checkbox\"> </a> 

In essence, a link that sends data via ajax (Pts do not want to touch id, since it is with data) Inside the link is a checkbox. Click and remove the checkboxes - the data is sent, all fun.

Is it possible to replace the checkbox with text, so that when you press / release a div, the text will change the style properties? (hunt not to hurt ajax)

 // не нажали <a style=\"{cursor:pointer;display:inline;}\" id=\"si_aaconf\"> <div style=\"тут_я_чего_ни_будь_напишу_1\">слово</div> </a> // нажали, стиль другой <a style=\"{cursor:pointer;display:inline;}\" id=\"si_aaconf\"> <div style=\"тут_я_чего_ни_будь_напишу_2\">слово</div> </a> 

those. something like a checkbox similarity turns out - you can see what is pressed and what is not

  • Why do you have quotes {,} in styles? Plus, where should the styles for the div come from? - lampa
  • This is for ajax, it works this way more correctly (besides, the hashcode gurus wrote it that way - it works, I dare not argue). div - well, just write: background-color: #FFFFFF; background-color: # 4488CC; - sergey

1 answer 1

If you want to get an element that is in an element, then it is simple:

js

 function getElem(elem) { var elems = elem.getElementsByTagName('div'); var first_el = elems[0]; if(first_el.getAttribute('active') == undefined || first_el.getAttribute('active') == '0') { first_el.style.color = 'red'; first_el.setAttribute('active', '1'); } else { first_el.style.color = 'blue'; first_el.setAttribute('active', '0'); } } 

html

 <a style=\"{cursor:pointer;display:inline;}\" id=\"si_aaconf\" onclick="getElem(this);"> <div style=\"тут_я_чего_ни_будь_напишу_2\">слово</div> </a> 
  • works! unfortunately only in one direction works. because You can click, if you press the second time back the style does not change, and unfortunately the style is registered Pts. strictly (guilty. example cited only with background-color) - sergey
  • one
    And here we take, but add an attribute to the tag. With js, it will check which value is set for this attribute and substitute the style we need. Updated post. - lampa
  • brilliant! Now I’ll try to fix the style on the class myself. asked wrong, although not special in js. I will be glad if someone helps - sergey
  • so as not to multiply the themes , please help, change the style to class, since JS did not understand c classes, that would switch classes - sergey
  • elem.className = 'traTaTa'; - lampa