in Education by
How can i replace a string that contain symbol to a class css? HTML
JQUERY p= '@.class-two'; $('#container').find('.class-one' + ReplaceString(p)).css("background-color", "red"); alert(ReplaceString(p)); // \@\.class-two function ReplaceString (mystring) { return mystring.replace( /(:|\.|\[|\]|,|=|@)/g, "\\" ); } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I think, you are struggeling with the jQuery selector. Your replacement does work fine for me. I just removed the backslashes as replacement: function ReplaceString (mystring) { return mystring.replace( /(:|\.|\[|\]|,|=|@)/g, "" ); } Then you have to modify your jQuery selector. If you are having more than one class, then seperate them by comma: $('#container').find('.class-one,.' + ReplaceString(p)).css("background-color", "red"); Here is the full code I tried. It worked fine for me: p= '@.class-two'; $('#container').find('.class-one,.' + ReplaceString(p)).css("background-color", "red"); function ReplaceString (mystring) { return mystring.replace( /(:|\.|\[|\]|,|=|@)/g, "" ); } See the fiddle: https://jsfiddle.net/dnsnx/h3ajdmge/

Related questions

0 votes
    We are in the process to update an existing WordPress website and imported posts from one site to another. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    We are in the process to update an existing WordPress website and imported posts from one site to another. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    We are in the process to update an existing WordPress website and imported posts from one site to another. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    We are in the process to update an existing WordPress website and imported posts from one site to another. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    How can I replace a specific text with HTML objects? example: var text = "some text to replace ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 25, 2022 in Education by JackTerrance
0 votes
    How can I replace a specific text with HTML objects? example: var text = "some text to replace ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    I am using wordpress, and some pages are using page-template, which is almost full HTML without . Now ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I want to truncate a string in Smarty This is the scenario: The string is "Test!abc". Maximum ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I have a question about how to change web pages with a Chrome extension. After reading some info I ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    c. To copy a formula in Microsoft Excel, you select the cell and drag this symbol that appears on the lower ... 7 computer please help Select the correct answer from above options...
asked Dec 28, 2021 in Education by JackTerrance
0 votes
    This question already has answers here: Find and replace strings in vim on multiple lines (11 answers) Vim ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    Today I found out that putting strings in a resource file will cause them to be treated as literals, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Today I found out that putting strings in a resource file will cause them to be treated as literals, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Today I found out that putting strings in a resource file will cause them to be treated as literals, ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Echo $var gives me something like http://342.234.243.142/data/somethingmore/ IP-address everytime is ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 28, 2022 in Education by JackTerrance
...