• Resolved nathalizator

    (@nathalizator)


    I am trying to select with query a cff field :

    jQuery( 'select#fieldname6_1' ).css( "background", "red" );

    I am able to select the div until #fieldlist_1 but then when i try to select class, it’s not working …

    Also, when i just add the select tag such as

    jQuery( 'select' ).css( "color", "red" );

    I’m adding this in my theme custom js section but not working, no error in js console.

    Anyway, i am trying in fact to add the “selected” attribut to one of my option drop down list but i’m not even able to select the class with jquery :/

    • This topic was modified 9 years, 4 months ago by nathalizator.
    • This topic was modified 9 years, 4 months ago by nathalizator.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello,

    The selector would be simply:

    jQuery( '#fieldname6_1' ).css( "background", "red" );

    I don’t know why you are assigning the colors with jQuery, and not with CSS rules. However, as I don’t know if your theme is assigning a color to the “SELECT” tags with the modifier “!important”, I recommend you assign the color as follows:

    jQuery( 'select' ).attr( 'style', 'color:red !important;' );

    Best regards.

    Thread Starter nathalizator

    (@nathalizator)

    Thanks ! All right, i think i was trying css without !important so it was not working.
    In fact i was trying to set the selected option of my form ACCORDING TO THE PAGE where the form is shown.

    I have found a solution that might be a bit messy but it works. The idea is to simply add a class to each of my post page for example :
    .porsche_cayman for porsche cayman post page
    .lamborghini_aventador for lamborghini aventador

    and then creat all the line and changing the class each time and the eq(number) that refer to vehicle .

    jQuery('div.porsche_cayman #fieldname6_1 option').eq(1).prop('selected', true);
    jQuery('div.lamborghini_aventador #fieldname6_1 option').eq(1).prop('selected', true);

    Do you think there is a solution where i could simply compare the page title with the <option> name attribut so the selected attribut could be set according to the page title?

    For example if my form is in the page porsche cayman which i got with echo get_the_title(); , how can add the selected attribut to the right <option> with the name porsche cayman ?

    I can’t see any name attribut on the form, only a vt= .

    • This reply was modified 9 years, 4 months ago by nathalizator.
    • This reply was modified 9 years, 4 months ago by nathalizator.
    • This reply was modified 9 years, 4 months ago by nathalizator.
    Thread Starter nathalizator

    (@nathalizator)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Unable to select cff class with jquery ?’ is closed to new replies.