Click here to Skip to main content
15,905,233 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
I Create this code for replace something and show a button :
JavaScript
var text = $(item).html().replace(exp, "<button onclick='alert('hi')' id='btnac' href='$1' >Click to Accept Voice Chat</button>");


But in page I get this and I cant show alert on any function :

XML
<button onclick="alert(" hi')'="" id="btnac" href="www.example.com">Click to Accept Voice Chat</button>
Posted
Updated 10-Jan-15 23:38pm
v3
Comments
Kornfeld Eliyahu Peter 11-Jan-15 5:32am    
And? what went wrong?
‫محم د‬‎ 11-Jan-15 5:36am    
Excuse me ! Completed
Kornfeld Eliyahu Peter 11-Jan-15 5:39am    
I can see some syntax errors around the alert - wrongly mixed double- and single-quotes? Please check it...
‫محم د‬‎ 11-Jan-15 5:43am    
I can see it ! But How I can solve it ? I just use single quotes !
Kornfeld Eliyahu Peter 11-Jan-15 5:57am    
Try this:
<button onclick='alert(\"hi\")' id='btnac' href='$1'>Click to Accept Voice Chat</button>

1 solution

Instead of onclick="alert(" hi')'="", it should be onclick="alert('hi')". Anyway, 1) using alert in production is a bad idea, 2) alert doesn't provide a way for user confirmation.

Better use, for example, jQuery dialog: http://jqueryui.com/dialog[^].

DOM manipulation also should be done more accurately. Even if yours works, it makes the functionality poorly supportable, because it depends too much on existing content and your exp. It would be more reliable to take a node found by its order, remove it, and replace what you need (I don't know why though). Please refer to http://api.jquery.com/category/manipulation[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900