html - How can I detect if an element had it's css changed by jquery? -


First of all, tell me what I'm trying to do. I have a line from poetry and need to click on the word "stressed". When you click on a word, jQuery does bold. I have a submit button and I should do something if you have the correct word bold, when the button is clicked. I have detected that there is a focus on the item, or if the item has been clicked but nothing is working.

  $ ("# w4"). (IEng.et ('click'), function () {$ (this). Data ('clicked', true);}); $ ('# W1'). (IEng.et ('click'), function () {$ (this) .Css ("font-weight", "bold"); $ ('# w2') CSS ("font-weight", "normal" $ ('# W3'); $ ('font-weight', 'normal'); $ ('# w4'). CSS ("font-weight", "normal"); $ ('# w5 '). CSS ("font-weight", "normal");}); $ ('# W2') (IEng.et ('click'), function () {$ (this) .Css ("font-weight", "bold"); $ ('# w1') CSS ("font-weight", "normal" $ ('# W3'); $ ('font-weight', 'normal'); $ ('# w4'). CSS ("font-weight", "normal"); $ ('# w5 '). CSS ("font-weight", "normal");}); $ ('# W3') (IEng.et ('click'), function () {$ (this) .Css ("font-weight", "bold"); $ ('# w1') CSS ("font-weight", "normal" $ ('# W2'); $ ('font-weight', 'normal'); $ ('# w4'). CSS ("font-weight", "normal"); $ ('# w5 '). CSS ("font-weight", "normal");}); $ ('# w4') ("Font-weight", "bold"); $ ('# w1') CSS ("font-weight", "normal" $ ('Font-weight', 'normal'); $ ('# w3'). CSS ("font-weight", "normal"); $ ('# w5' ). CSS ("font-weight", "normal");}); $ ('# W5') (IEng.et ('click'), function () {$ (this) .css ("font-weight", "bold"); $ ('# w1') CSS ("font-weight", "normal" $ ('# W2'); $ ('font-weight', 'normal'); $ ('# w3'). CSS ("font-weight", "normal"); $ ('# w4 '). CSS ("font-weight", "normal");});   

In addition, if it is relevant, then I am using a program called Hypay to generate the html5 code.

Any help would be appreciated. Thank you ..

I think each word is wrapped in its element (probably a & lt; span & gt; ) above Based on your ID names given. It appears that w {value} will specify the word number in the poem. If this is wrong then correct me, in that case, your solution should be easy.

Unless your initial style is a & lt; Style & gt; In the tag or the external stylesheet, the following solutions should work.

When jQuery adds styles to an element, it adds them inline using the style = "..." attribute. Select this type of attribute when you select your bold element:

  var word = $ ('div [style]'). Text (); The word with the   

style attribute is the user's choice, once selected, .text () to drag the selected word shown above.

Edit:

Comment on the other answer, it seems that you want to compare the correct word in the verse (word 4) of the selected word . Do the following for:

  if ($ ('div [style]'). Text () === $ ('# w4') .text ()) {... / / To handle the correct response) and {... // handle feedback}}   

I know that this may be a big leap, but by changing your logic Can prove future. If those words can be translated, you can base your argument on the ID value of the element instead:

  if ($ ('div [style]') [ 0] .id = "w4") {... // is handling the correct response} and {... // get an error error}   

2 Edit: Depending on the comment thread below, it appears that early inline styles are automatically generated and can not be removed. To be with this situation, we can change our selector for a specific CSS property (a bit but that does work):

Change:

  $ ('Div [style]')   

to:

  $ ('div [style * = "font-weight: bold"]')   

References:




Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -