Obtener ID de un elemento por JS en un elemento del módulo
-
10-12-2019 - |
Pregunta
No sé si elijo el título correcto.
Aquí está mi problema, he creado un módulo en qué puedo poner mi JS / CSS (>http://img4.hostingpics.net/pics/586674modulejs.png ) Y me gustaría obtener la identificación de mis elementos HTML.SharePoint está agregando algún tipo de caracteres de matriz a Mis elementos, y cada uno de ellos se ve similar a esto: ctl40_g_fa43dd10_b395_40e7_98cd_a52585a208c5_Timesheet
Así que solía obtener la identificación en mi página web usando el cliend de mi artículo.Aquí hay un ejemplo de lo que estaba haciendo antes de mover mi JS a un archivo separado.(Estaba haciendo JS / estilo en el archivo ACSX de WebPart, pero obtuve algunos problemas y tuve que mover mi JS / estilo en una carpeta separada).
js
$("#<%#Timesheet.ClientID%>").find("tbody").find("tr").each(function () {
if ($(this).attr("data-name") == "timesheetEntryTotal") {
$(this).before(tr);
return false;
}
});
css
#<%#Timesheet.ClientID%> > tbody > tr > td {
height: 30px;
background-color: #F6F6F6;
}
Pero ahora que moví mi JS / CS a una carpeta separada, no puedo usar <% ...%>.Entonces, ¿cómo puedo obtener la identificación de mis elementos ahora?
por favor ayuda. Gracias de antemano.
Solución
I've found another solution is to use the HTML5 custom attribute like data-name.
So instead of getting the id like this $("#<%#Timesheet.ClientId%>")
, I now do $("table[data-id='Timesheet']")
Same thing for the css selector.
table[data-id="Timesheet"] > tbody > tr > td {
height: 30px;
background-color: #F6F6F6;
}
Otros consejos
If you're using jQuery to select element, you could use '$' for ends with.
$("table[id$='Timesheet']")
You could do similar for CSS:
table[id$="Timesheet"] > tbody > tr > td {
height: 30px;
background-color: #F6F6F6;
}